Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for showprnt.vbs

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

  1. ' ShowPrnT.vbs,  Version 1.00
  2. ' Display all installed printers in a TAB delimited format.
  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 = "Printer Name:" & vbTab _
  29.        & "Port Name:"    & vbTab _
  30.        & "Driver Name:"  & vbTab _
  31.        & "Server Name:"  & vbTab _
  32.        & "Share Name:"   & vbCrLf
  33.  
  34. ' We'll use our own error handling
  35. On Error Resume Next
  36.  
  37. ' Connect to specified computer
  38. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  39.  
  40. ' Display error number and description if applicable
  41. If Err Then ShowError
  42.  
  43. ' Query installed printers' properties
  44. Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
  45.  
  46. ' Display error number and description if applicable
  47. If Err Then ShowError
  48.  
  49. ' Format output for display
  50. For Each objItem in colItems
  51. 	strMsg = strMsg _
  52. 	       & objItem.Name       & vbTab _
  53. 	       & objItem.PortName   & vbTab _
  54. 	       & objItem.DriverName & vbTab _
  55. 	       & objItem.ServerName & vbTab _
  56. 	       & objItem.ShareName  & vbCrLf
  57. Next
  58.  
  59. ' Display the results
  60. WScript.Echo strMsg
  61.  
  62. 'Done
  63. WScript.Quit(0)
  64.  
  65.  
  66. Sub ShowError()
  67. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  68. 	         Err.Description & vbCrLf & vbCrLf
  69. 	Syntax
  70. End Sub
  71.  
  72.  
  73. Sub Syntax()
  74. 	strMsg = strMsg & vbCrLf _
  75. 	       & "ShowPRNT.vbs,  Version 1.01" & vbCrLf _
  76. 	       & "Display installed printers properties for " _
  77. 	       & "any computer" & vbCrLf _
  78. 	       & "on the network in a tab delimited format" _
  79. 	       & vbCrLf & vbCrLf _
  80. 	       & "Usage:  CSCRIPT  //NOLOGO  SHOWPRNT.VBS  " _
  81. 	       & "[ computer_name ]" & vbCrLf & vbCrLf _
  82. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  83. 	       & " is the optional name of a remote" & vbCrLf _
  84. 	       & "        computer (default is local computer " _
  85. 	       & "name)" & vbCrLf & vbCrLf _
  86. 	       & "Written by Rob van der Woude" & vbCrLf _
  87. 	       & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  88. 	       & "Created with Microsoft's Scriptomatic tool" & vbCrLf _
  89. 	       & "http://www.microsoft.com/technet/treeview/default.asp" _
  90. 	       & "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
  91. 	WScript.Echo strMsg
  92. 	WScript.Quit(1)
  93. End Sub
  94.  

page last uploaded: 2017-08-21, 14:26