Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for canonrep.vbs

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

  1. Option Explicit
  2.  
  3. Dim blnTimedOut, i, intTimeOut, objIE, objRE, strHTML, strIP, strMsg, strURL
  4.  
  5. If WScript.Arguments.Unnamed.Count <> 1 Then Syntax
  6. If WScript.Arguments.Named.Count    > 0 Then Syntax
  7.  
  8. strIP      = WScript.Arguments.Item(0)
  9. strURL     = "http://" & strIP & "/en/pages/d_cbody.htm"
  10. strMsg     = ""
  11. intTimeOut = 30
  12.  
  13. Set objIE = CreateObject( "InternetExplorer.Application" )
  14.  
  15. objIE.Visible = False
  16. objIE.Navigate2 strURL
  17.  
  18. ' Wait till IE is ready
  19. i = 0
  20. blnTimedOut = False
  21. Do While objIE.Busy
  22. 	WScript.Sleep 100
  23. 	i = i + 1
  24. 	' Time out after the specified number of seconds
  25. 	If i > CInt( intTimeOut * 10 ) Then
  26. 		blnTimedOut = True
  27. 		Exit Do
  28. 	End If
  29. Loop
  30.  
  31. ' Retrieve the URL's text and save it in an array
  32. If Not blnTimedOut Then
  33. 	strHTML = objIE.Document.Body.InnerHTML
  34. End If
  35.  
  36. Set objRE = New RegExp
  37.  
  38. objRE.Global     = False
  39. objRE.IgnoreCase = True
  40. objRE.Pattern    = ">write_value\(\""(101)\"", (\d+)\);<(\n|.)+>write_value\(\""(103)\"", (\d+)\);<(\n|.)+>write_value\(\""(104)\"", (\d+)\);<"
  41.  
  42. Set objMatch = objRE.Execute( strHTML )
  43.  
  44. If objMatch.Count = 1 Then
  45. 	strMsg = strIP & vbCrLf _
  46. 	       & objMatch.Item(0).Submatches(0) & vbTab & "Total1" & vbTab & objMatch.Item(0).Submatches(1) & vbCrLf _
  47. 	       & objMatch.Item(0).Submatches(3) & vbTab & "Total (Large)" & vbTab & objMatch.Item(0).Submatches(4) & vbCrLf _
  48. 	       & objMatch.Item(0).Submatches(6) & vbTab & "Total (Small)" & vbTab & objMatch.Item(0).Submatches(7) & vbCrLf
  49.     WScript.Echo strMsg
  50. End If
  51.  
  52. objIE.Quit
  53. Set objIE    = Nothing
  54. Set objMatch = Nothing
  55. Set objRE    = Nothing
  56.  
  57.  
  58. Sub Syntax
  59. 	strMsg = vbCrLf _
  60. 	       & "CanonReport.vbs,  Version 1.01" _
  61. 	       & vbCrLf _
  62. 	       & "Display Canon IR3320 printers' total print output" _
  63. 	       & vbCrLf _
  64. 	       & "(may or may not work on other Canon printer models)" _
  65. 	       & vbCrLf & vbCrLf _
  66. 	       & "Usage:  CSCRIPT.EXE  //NoLogo  CANONREP.VBS  ip_address" _
  67. 	       & vbCrLf & vbCrLf _
  68. 	       & "Where:  ""ip_address""  is the IP address of the printer" _
  69. 	       & vbCrLf & vbCrLf _
  70. 	       & "Written by Rob van der Woude" & vbCrLf _
  71. 	       & "http://www.robvanderwoude.com"
  72. 	WScript.Echo strMsg
  73. 	WScript.Quit 1
  74. End Sub
  75.  

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