(view source code of comports.vbs as plain text)
' Check command line parametersSelect Case WScript.Arguments.Count
Case 0
' Default if none specified is local computer (".")Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
strComputer = objItem.Name
NextCase 1
' Command line parameter can either be a computer ' name or "/?" to request online helpstrComputer = UCase( Wscript.Arguments(0) )
if InStr( strComputer, "?" ) > 0 Then Syntax
Case Else
' Maximum is 1 command line parameterSyntax
End Select
' Header line for screen outputstrMsg = vbCrLf & "Serial ports summary for " & strComputer & ":" & vbCrLf & vbCrLf
' Enable error handlingOn Error Resume Next
' Connect to specified computerSet objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
' Display error number and description if applicableIf Err Then ShowError
' Query serial ports propertiesSet colItems = objWMIService.ExecQuery( "Select * From Win32_SerialPort", , 48 )
' Display error number and description if applicableIf Err Then ShowError
' Format results for displayFor Each objItem in colItems
strMsg = strMsg _& "DeviceID : " & objItem.DeviceID & vbCrLf _
& "ProviderType : " & objItem.ProviderType & vbCrLf _
& "Description : " & objItem.Description & vbCrLf & vbCrLf
Next' Display resultsWScript.Echo strMsg
'DoneWScript.Quit(0)
Sub ShowError()
strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & vbCrLf
Syntax
End Sub
Sub Syntax()
strMsg = strMsg & vbCrLf _
& "ComPorts.vbs, Version 1.00" & vbCrLf _
& "Display basic serial port summary for any WMI " _
& "enabled computer on the network" & vbCrLf & vbCrLf _
& "Usage: CSCRIPT //NOLOGO COMPORTS.VBS " _
& "[ computer_name ]" & vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "computer_name" & Chr(34) _
& " is the optional name of a remote" & vbCrLf _
& " computer (default is local computer " _
& "name)" & vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
& "Created with Microsoft's Scriptomatic tool" & vbCrLf _
& "http://www.microsoft.com/technet/treeview/default.asp" _
& "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
WScript.Echo strMsg
WScript.Quit(1)
End Sub
page last modified: 2025-10-11; loaded in 0.0064 seconds