Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for comports.vbs

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

  1. ' Check command line parameters
  2. Select Case WScript.Arguments.Count
  3. 	Case 0
  4. 		' Default if none specified is local computer (".")
  5. 		Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  6. 		Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  7. 		For Each objItem in colItems
  8. 			strComputer = objItem.Name
  9. 		Next
  10. 	Case 1
  11. 		' Command line parameter can either be a computer
  12. 		' name or "/?" to request online help
  13. 		strComputer = UCase( Wscript.Arguments(0) )
  14. 		if InStr( strComputer, "?" ) > 0 Then Syntax
  15. 	Case Else
  16. 		' Maximum is 1 command line parameter
  17. 		Syntax
  18. End Select
  19.  
  20. ' Header line for screen output
  21. strMsg = vbCrLf & "Serial ports summary for " & strComputer & ":" & vbCrLf & vbCrLf
  22.  
  23. ' Enable error handling
  24. On Error Resume Next
  25.  
  26. ' Connect to specified computer
  27. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  28. ' Display error number and description if applicable
  29. If Err Then ShowError
  30.  
  31. ' Query serial ports properties
  32. Set colItems = objWMIService.ExecQuery( "Select * From Win32_SerialPort", , 48 )
  33. ' Display error number and description if applicable
  34. If Err Then ShowError
  35.  
  36. ' Format results for display
  37. For Each objItem in colItems
  38. 	strMsg = strMsg _
  39. 	       & "DeviceID         : " & objItem.DeviceID & vbCrLf _
  40. 	       & "ProviderType     : " & objItem.ProviderType & vbCrLf _
  41. 	       & "Description      : " & objItem.Description & vbCrLf & vbCrLf
  42. Next
  43.  
  44. ' Display results
  45. WScript.Echo strMsg
  46.  
  47. 'Done
  48. WScript.Quit(0)
  49.  
  50.  
  51. Sub ShowError()
  52. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  53. 	         Err.Description & vbCrLf & vbCrLf
  54. 	Syntax
  55. End Sub
  56.  
  57.  
  58. Sub Syntax()
  59. 	strMsg = strMsg & vbCrLf _
  60. 	       & "ComPorts.vbs,  Version 1.00" & vbCrLf _
  61. 	       & "Display basic serial port summary for any WMI " _
  62. 	       & "enabled computer on the network" & vbCrLf & vbCrLf _
  63. 	       & "Usage:  CSCRIPT  //NOLOGO  COMPORTS.VBS  " _
  64. 	       & "[ computer_name ]" & vbCrLf & vbCrLf _
  65. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  66. 	       & " is the optional name of a remote" & vbCrLf _
  67. 	       & "        computer (default is local computer " _
  68. 	       & "name)" & vbCrLf & vbCrLf _
  69. 	       & "Written by Rob van der Woude" & vbCrLf _
  70. 	       & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  71. 	       & "Created with Microsoft's Scriptomatic tool" & vbCrLf _
  72. 	       & "http://www.microsoft.com/technet/treeview/default.asp" _
  73. 	       & "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
  74. 	WScript.Echo strMsg
  75. 	WScript.Quit(1)
  76. End Sub
  77.  

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