Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for updatedpp.vbs

(view source code of updatedpp.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim intAnswer
  4. Dim objFSO, wshShell
  5. Dim strLatest, strPath, strProg, strPrompt, strTitle, strVersion
  6.  
  7. If WScript.Arguments.Count > 0 Then Syntax
  8.  
  9. Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
  10. Set wshShell = CreateObject( "Wscript.Shell" )
  11.  
  12. On Error Resume Next
  13. strPath = wshShell.RegRead( "HKEY_LOCAL_MACHINE\SOFTWARE\Canon\DPP\InstallPath" )
  14. If Err Then strPath = wshShell.RegRead( "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Canon\DPP\InstallPath" )
  15. On Error Goto 0
  16. strProg = objFSO.BuildPath( strPath, "DPPViewer.exe" )
  17. strVersion = objFSO.GetFileVersion( strProg )
  18. strLatest = GetDPPVersion( )
  19.  
  20. If Left( strVersion, Min( Len( strLatest ), Len( strVersion ) ) ) = Left( strLatest, Min( Len( strLatest ), Len( strVersion ) ) ) Then
  21. 	WScript.Echo "Digital Photo professional " & strVersion & " is up-to-date"
  22. Else
  23. 	strPrompt = "Version " & strLatest & " of Digital Photo professional is newer than the installed " & strVersion & " version." _
  24. 	          & vbCrLf & vbCrLf _
  25. 	          & "Do you want to download the latest version?"
  26. 	strTitle  = "DPP update available"
  27. 	If MsgBox( strPrompt, vbYesNoCancel, strTitle ) = vbYes Then
  28. 		wshShell.Run "http://software.canon-europe.com/"
  29. 	End If
  30. End If
  31.  
  32. Function GetDPPVersion( )
  33. ' This function returns the latest DPP version as string
  34. ' by reading WikiPedia's Digital Photo Professional page.
  35. ' If an error occurs, the returned version will be "999999".
  36. ' Written by Rob van der Woude
  37. ' http://www.robvanderwoude.com
  38. 	Dim objHTTP, objMatch, objRE, objSubMatch, strHTML, strUserAgent, strVersion
  39. 	' Initial return string, in case an error occurs
  40. 	strVersion = "999999"
  41. 	' Use WinHTTP to read the text from WikiPedia's Digital Photo Professional page
  42. 	Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  43. 	objHTTP.Open "GET", "http://en.wikipedia.org/wiki/Digital_Photo_Professional", False
  44. 	strUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3"
  45. 	objHTTP.SetRequestHeader "UserAgent", strUserAgent
  46. 	objHTTP.Send
  47. 	If objHTTP.Status = 200 Then
  48. 		' If the page was returned, use a regular expression
  49. 		' to extract DPP's current version number
  50. 		strHTML = objHTTP.ResponseText
  51. 		Set objRE = New RegExp
  52. 		objRE.Pattern = "Stable release</a></t[dh]>\s*<td[^>]*>(:?(\d+\.\d+\.\d+) \(<a [^>]+>[^<]+</a>\), )*(\d+\.\d+\.\d+) \(<a [^>]+>Windows</a>\)"
  53. 		objRE.IgnoreCase = False
  54. 		objRE.Global = True
  55. 		Set objMatch = objRE.Execute( strHTML )
  56. 		If objMatch.Count > 0 Then
  57. 			For Each objSubMatch In objMatch.Item(0).Submatches
  58. 				strVersion = objSubMatch
  59. 			Next
  60. 		End If
  61. 		Set objMatch = Nothing
  62. 		Set objRE = Nothing
  63. 	End If
  64. 	Set objHTTP = Nothing
  65. 	' Return the result
  66. 	GetDPPVersion = strVersion
  67. End Function
  68.  
  69.  
  70. Function Max( num1, num2 )
  71. 	If num1 > num2 Then
  72. 		Max = num1
  73. 	Else
  74. 		Max = num2
  75. 	End If
  76. End Function
  77.  
  78.  
  79. Function Min( num1, num2 )
  80. 	If num1 < num2 Then
  81. 		Min = num1
  82. 	Else
  83. 		Min = num2
  84. 	End If
  85. End Function
  86.  
  87.  
  88. Sub Syntax
  89. 	Dim strMsg
  90. 	strMsg = "UpdateDPP.vbs,  Version 1.01" _
  91. 	       & vbCrLf _
  92. 	       & "Check if a newer version of Canon Digital Photo Professional (DPP) is available" _
  93. 	       & vbCrLf & vbCrLf _
  94. 	       & "Usage:  UpdateDPP.vbs" _
  95. 	       & vbCrLf & vbCrLf _
  96. 	       & "Note:   This is a demo script, hardcoded for Digital Photo Professional." _
  97. 	       & vbCrLf _
  98. 	       & "        It depends on WikiPedia's DPP page being up to date." _
  99. 	       & vbCrLf _
  100. 	       & "        It MAY fail with any new version, and WILL if the WikiPedia" _
  101. 	       & vbCrLf _
  102. 	       & "        website layout is modified." _
  103. 	       & vbCrLf _
  104. 	       & "        You are encouraged to modify the code to your own requirements." _
  105. 	       & vbCrLf & vbCrLf _
  106. 	       & "Written by Rob van der Woude" _
  107. 	       & vbCrLf _
  108. 	       & "http://www.robvanderwoude.com"
  109. 	WScript.Echo strMsg
  110. 	WScript.Quit 1
  111. End Sub
  112.  

page last modified: 2024-04-16; loaded in 0.0130 seconds