Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for showprn.vbs

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

  1. ' ShowPrn.vbs,  Version 1.00
  2. ' Display all installed printers.
  3. '
  4. ' Written by Rob van der Woude
  5. ' http://www.robvanderwoude.com
  6.  
  7.  
  8. ' Check command line arguments
  9. Select Case WScript.Arguments.Count
  10. 	Case 0
  11. 		' Default if none specified is local computer (".")
  12. 		Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  13. 		Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  14. 		For Each objItem in colItems
  15. 			strComputer = objItem.Name
  16. 		Next
  17. 	Case 1
  18. 		' Command line parameter can either be a computer name
  19. 		' or "/?" to request online help
  20. 		strComputer = Wscript.Arguments(0)
  21. 		if InStr( strComputer, "?" ) > 0 Then Syntax
  22. 	Case Else
  23. 		' Maximum is 1 command line parameter
  24. 		Syntax
  25. End Select
  26.  
  27. ' Initialize variable
  28. strMsg = ""
  29.  
  30. ' We'll use our own error handling
  31. On Error Resume Next
  32.  
  33. ' Connect to specified computer
  34. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  35.  
  36. ' Display error number and description if applicable
  37. If Err Then ShowError
  38.  
  39. ' Query installed printers' properties
  40. Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
  41.  
  42. ' Display error number and description if applicable
  43. If Err Then ShowError
  44.  
  45. ' Format output for display
  46. For Each objItem in colItems
  47. 	strMsg = strMsg & vbCrLf _
  48. 	       & "Printer Name :  " & objItem.Name & vbCrLf _
  49. 	       & "Port Name    :  " & objItem.PortName & vbCrLf _
  50. 	       & "Driver Name  :  " & objItem.DriverName & vbCrLf _
  51. 	       & "Server Name  :  " & objItem.ServerName & vbCrLf _
  52. 	       & "Share Name   :  " & objItem.ShareName & vbCrLf
  53. Next
  54.  
  55. ' Display the results
  56. WScript.Echo strMsg
  57.  
  58. 'Done
  59. WScript.Quit(0)
  60.  
  61.  
  62. Sub ShowError()
  63. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  64. 	         Err.Description & vbCrLf & vbCrLf
  65. 	Syntax
  66. End Sub
  67.  
  68.  
  69. Sub Syntax()
  70. 	strMsg = strMsg & vbCrLf _
  71. 	       & "ShowPRN.vbs,  Version 1.00" & vbCrLf _
  72. 	       & "Display installed printers properties for " _
  73. 	       & "any computer on the network" & vbCrLf & vbCrLf _
  74. 	       & "Usage:  CSCRIPT  //NOLOGO  SHOWPRN.VBS  " _
  75. 	       & "[ computer_name ]" & vbCrLf & vbCrLf _
  76. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  77. 	       & " is the optional name of a remote" & vbCrLf _
  78. 	       & "        computer (default is local computer " _
  79. 	       & "name)" & vbCrLf & vbCrLf _
  80. 	       & "Written by Rob van der Woude" & vbCrLf _
  81. 	       & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  82. 	       & "Created with Microsoft's Scriptomatic tool" & vbCrLf _
  83. 	       & "http://www.microsoft.com/technet/treeview/default.asp" _
  84. 	       & "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
  85. 	WScript.Echo strMsg
  86. 	WScript.Quit(1)
  87. End Sub
  88.  

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