(view source code of updatedpp.vbs as plain text)
Option Explicit
Dim intAnswer
Dim objFSO, wshShell
Dim strLatest, strPath, strProg, strPrompt, strTitle, strVersion
If WScript.Arguments.Count > 0 Then Syntax
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set wshShell = CreateObject( "Wscript.Shell" )
On Error Resume Next
strPath = wshShell.RegRead( "HKEY_LOCAL_MACHINE\SOFTWARE\Canon\DPP\InstallPath" )
If Err Then strPath = wshShell.RegRead( "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Canon\DPP\InstallPath" )
On Error Goto 0
strProg = objFSO.BuildPath( strPath, "DPPViewer.exe" )
strVersion = objFSO.GetFileVersion( strProg )
strLatest = GetDPPVersion( )
If Left( strVersion, Min( Len( strLatest ), Len( strVersion ) ) ) = Left( strLatest, Min( Len( strLatest ), Len( strVersion ) ) ) Then
WScript.Echo "Digital Photo professional " & strVersion & " is up-to-date"
Else
strPrompt = "Version " & strLatest & " of Digital Photo professional is newer than the installed " & strVersion & " version." _
& vbCrLf & vbCrLf _
& "Do you want to download the latest version?"
strTitle = "DPP update available"
If MsgBox( strPrompt, vbYesNoCancel, strTitle ) = vbYes Then
wshShell.Run "http://software.canon-europe.com/"
End If
End If
Function GetDPPVersion( )
' This function returns the latest DPP version as string
' by reading WikiPedia's Digital Photo Professional page.
' If an error occurs, the returned version will be "999999".
' Written by Rob van der Woude
' http://www.robvanderwoude.com
Dim objHTTP, objMatch, objRE, objSubMatch, strHTML, strUserAgent, strVersion
' Initial return string, in case an error occurs
strVersion = "999999"
' Use WinHTTP to read the text from WikiPedia's Digital Photo Professional page
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
objHTTP.Open "GET", "http://en.wikipedia.org/wiki/Digital_Photo_Professional", False
strUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3"
objHTTP.SetRequestHeader "UserAgent", strUserAgent
objHTTP.Send
If objHTTP.Status = 200 Then
' If the page was returned, use a regular expression
' to extract DPP's current version number
strHTML = objHTTP.ResponseText
Set objRE = New RegExp
objRE.Pattern = "Stable release</a></t[dh]>\s*<td[^>]*>(:?(\d+\.\d+\.\d+) \(<a [^>]+>[^<]+</a>\), )*(\d+\.\d+\.\d+) \(<a [^>]+>Windows</a>\)"
objRE.IgnoreCase = False
objRE.Global = True
Set objMatch = objRE.Execute( strHTML )
If objMatch.Count > 0 Then
For Each objSubMatch In objMatch.Item(0).Submatches
strVersion = objSubMatch
Next
End If
Set objMatch = Nothing
Set objRE = Nothing
End If
Set objHTTP = Nothing
' Return the result
GetDPPVersion = strVersion
End Function
Function Max( num1, num2 )
If num1 > num2 Then
Max = num1
Else
Max = num2
End If
End Function
Function Min( num1, num2 )
If num1 < num2 Then
Min = num1
Else
Min = num2
End If
End Function
Sub Syntax
Dim strMsg
strMsg = "UpdateDPP.vbs, Version 1.01" _
& vbCrLf _
& "Check if a newer version of Canon Digital Photo Professional (DPP) is available" _
& vbCrLf & vbCrLf _
& "Usage: UpdateDPP.vbs" _
& vbCrLf & vbCrLf _
& "Note: This is a demo script, hardcoded for Digital Photo Professional." _
& vbCrLf _
& " It depends on WikiPedia's DPP page being up to date." _
& vbCrLf _
& " It MAY fail with any new version, and WILL if the WikiPedia" _
& vbCrLf _
& " website layout is modified." _
& vbCrLf _
& " You are encouraged to modify the code to your own requirements." _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit 1
End Sub
page last modified: 2024-04-16; loaded in 0.0130 seconds