Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for foxitver.vbs

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

  1. Option Explicit
  2.  
  3. If WScript.Arguments.Count > 0 Then Syntax
  4.  
  5. WScript.Echo "Latest version of Foxit Reader: " & GetFoxitReaderVersion( )
  6.  
  7.  
  8. Function GetFoxitReaderVersion( )
  9. ' This function returns the current Foxit Reader version
  10. ' as string by reading Foxit's version history page.
  11. ' If an error occurs, the returned version will be "0".
  12. ' Written by Rob van der Woude
  13. ' http://www.robvanderwoude.com
  14. 	Dim objHTTP, objMatch, objRE, strHTML, strUserAgent, strVersion
  15. 	' Initial return string, in case an error occurs
  16. 	GetFoxitReaderVersion = "0"
  17. 	' Use WinHTTP to read the text from Foxit's download page
  18. 	Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  19. 	'objHTTP.Open "GET", "http://www.foxitsoftware.com/pdf/reader_2/down_reader.htm", False
  20. 	objHTTP.Open "GET", "http://www.foxitsoftware.com/Secure_PDF_Reader/version_history.php", False
  21. 	strUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3"
  22. 	objHTTP.SetRequestHeader "UserAgent", strUserAgent
  23. 	objHTTP.Send
  24. 	If objHTTP.Status = 200 Then
  25. 		' If the page was returned, use a regular expression
  26. 		' to extract Foxit Reader's latest version number
  27. 		strHTML = objHTTP.ResponseText
  28. 		Set objRE = New RegExp
  29. 		objRE.Pattern = "<h[^>]+>Version History</h\d+>[\n\r\s]+<h[^>]+>What's New in Foxit Reader (\d+\.\d+\.\d+)</h\d+>"
  30. 		objRE.IgnoreCase = False
  31. 		objRE.Global = False
  32. 		Set objMatch = objRE.Execute( strHTML )
  33. 		If objMatch.Count > 0 Then
  34. 			strVersion = objMatch.Item(0).Submatches.Item(0)
  35. 		End If
  36. 		Set objMatch = Nothing
  37. 		Set objRE = Nothing
  38. 	End If
  39. 	Set objHTTP = Nothing
  40. 	' Return the result
  41. 	GetFoxitReaderVersion = strVersion
  42. End Function
  43.  
  44.  
  45. Sub Syntax
  46. 	Dim strMsg
  47. 	strMsg = "FoxitVer.vbs,  Version 2.00" _
  48. 	       & vbCrLf _
  49. 	       & "Read the latest available version of Foxit Reader from its version history page" _
  50. 	       & vbCrLf & vbCrLf _
  51. 	       & "Usage  :  FOXITVER.VBS" _
  52. 	       & vbCrLf & vbCrLf
  53. 	strMsg = strMsg & "Returns:  " & GetFoxitReaderVersion( ) & vbCrLf & vbCrLf
  54. 	strMsg = strMsg _
  55. 	       & "Note   :  This is a demo script, hardcoded for Foxit Reader." _
  56. 	       & vbCrLf _
  57. 	       & "          You are encouraged to modify the code to your own requirements." _
  58. 	       & vbCrLf & vbCrLf _
  59. 	       & "Written by Rob van der Woude" _
  60. 	       & vbCrLf _
  61. 	       & "http://www.robvanderwoude.com"
  62. 	WScript.Echo strMsg
  63. 	WScript.Quit 1
  64. End Sub
  65.  

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