(view source code of iscdwriter.vbs as plain text)
Option Explicit
Dim arrCapabilities, arrDrives, arrWriters
Dim blnIsCDWriter
Dim intCapability, intRC, intWriters
Dim colItems, objItem, objWMIService
Dim strArg, strDrive, strComputer, strMsg
If WScript.Arguments.Named.Count > 0 Then Syntax "" ' No command line switches
intRC = 0
intWriters = 0
strComputer = "."
Set arrDrives = CreateObject( "System.Collections.ArrayList" ) ' List of drives to be tested
Set arrWriters = CreateObject( "System.Collections.ArrayList" ) ' List of CD/DVD drives found
For Each strArg In WScript.Arguments.Unnamed
If Len( strArg ) = 2 Then
If Right( strArg, 1 ) = ":" Then
If arrDrives.Contains( UCase( strArg ) ) Then
Syntax "Duplicate argument """ & strArg & """"
Else
arrDrives.add UCase( strArg )
End If
Else
If strComputer = "." Then
strComputer = strArg
Else
Syntax "Duplicate computer name arguments """ & strComputer & """ and """ & strArg & """"
End If
End If
Else
If strComputer = "." Then
strComputer = strArg
Else
Syntax "Duplicate computer name arguments """ & strComputer & """ and """ & strArg & """"
End If
End If
Next
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_CDROMDrive" )
If arrDrives.Count = 0 Then
For Each objItem in colItems
arrDrives.Add objItem.Drive
Next
End If
For Each objItem in colItems
If arrDrives.Contains( UCase( objItem.Drive ) ) Then
For Each intCapability In objItem.Capabilities
If intCapability = 4 Then arrWriters.Add objItem.Drive
Next
End If
Next
Set colItems = Nothing
Set objWMIService = Nothing
strMsg = arrDrives.Count & " drive"
If arrDrives.count <> 1 Then strMsg = strMsg & "s"
strMsg = strMsg & " tested, " & arrWriters.Count & " CD/DVD writer"
If arrWriters.Count <> 1 Then strMsg = strMsg & "s"
strMsg = strMsg & " found:" & vbCrLf
For Each strDrive In arrDrives
If arrWriters.Contains( strDrive ) Then
strMsg = strMsg & vbTab & strDrive & vbTab & "CD/DVD writer" & vbCrLf
Else
strMsg = strMsg & vbTab & strDrive & vbTab & "is not a writer" & vbCrLf
End If
Next
WScript.Echo strMsg
intRC = arrWriters.Count
Set arrWriters = Nothing
Set arrDrives = Nothing
WScript.Quit intRC
Sub Syntax( strError )
Dim strMsg
If strError <> "" Then strMsg = vbCrLf & "ERROR: " & strError & vbCrLf
strMsg = strMsg _
& vbCrLf _
& "IsCDWriter.vbs, Version 1.00" _
& vbCrLf _
& "Check whether specified drives are CD/DVD writers or not" _
& vbCrLf & vbCrLf _
& "Usage:" & vbTab & "CSCRIPT.EXE IsCDWriter.vbs [ computer ] [ drive: [ drive: ... ] ]" _
& vbCrLf & vbCrLf _
& "Where:" & vbTab & "computer" & vbTab & "is the optional remote computer's name or IP address" _
& vbCrLf _
& " " & vbTab & " " & vbTab & "(default: the local computer)" _
& vbCrLf _
& " " & vbTab & "drive: " & vbTab & "is/are the CD/DVD drive(s) to be tested" _
& vbCrLf _
& " " & vbTab & " " & vbTab & "(default: all available CD/DVD drives)" _
& vbCrLf & vbCrLf _
& "Note: The return code equals the number of CD/DVD writers, or -1 for errors." _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit -1
End Sub
page last modified: 2024-04-16; loaded in 0.0086 seconds