(view source code of cdrom.vbs as plain text)
' Check command line parameters
Select 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
Next
Case 1
' Command line parameter can either be a computer name
' or "/?" to request online help
strComputer = Wscript.Arguments(0)
if InStr( strComputer, "?" ) > 0 Then Syntax
Case Else
' Maximum is 1 command line parameter
Syntax
End Select
' Set initial values of variables used
strMsg = " found on \\" & strComputer & ":"
intCount = 0
' Enable error handling
On Error Resume Next
' Connect to the computer
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
If Err Then DispErr
' Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where MediaType=11",,48)
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where DriveType=5",,48)
If Err Then DispErr
For Each objItem in colItems
intCount = intCount + 1
strMsg = strMsg & " " & objItem.Name
Next
' Format the screen output
If intCount = 1 Then
strDrive = "drive"
Else
strDrive = "drives"
End If
strMsg = vbCrLf & intCount & " CD-ROM " & strDrive & strMsg
' Display the result
WScript.Echo strMsg
' Done
WScript.Quit(0)
Sub DispErr
If Err.Number Then
WScript.Echo vbCrLf & "Error # " & CStr( Err.Number ) & _
" " & Err.Description
Err.Clear
Syntax
End If
End Sub
Sub Syntax
strMsg = vbCrLf & "CDROM.vbs, Version 1.10" & vbCrLf _
& "Display CD-ROM drive letters for any WMI enabled " _
& "computer on the network." & vbCrLf & vbCrLf _
& "Usage: CSCRIPT CDROM.VBS [ computer_name ]" _
& vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "computer_name" & Chr(34) _
& " is the name of a WMI enabled computer on the network" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com" & vbCrLf
WScript.Echo strMsg
WScript.Quit(1)
End Sub
page last modified: 2024-04-16; loaded in 0.0065 seconds