(view source code of iscdwriter.vbs as plain text)
Option ExplicitDim arrCapabilities, arrDrives, arrWritersDim blnIsCDWriterDim intCapability, intRC, intWritersDim colItems, objItem, objWMIServiceDim strArg, strDrive, strComputer, strMsgIf 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 & """"
ElsearrDrives.add UCase( strArg )
End If
ElseIf strComputer = "." Then
strComputer = strArg ElseSyntax "Duplicate computer name arguments """ & strComputer & """ and """ & strArg & """"
End If
End If
ElseIf strComputer = "." Then
strComputer = strArg ElseSyntax "Duplicate computer name arguments """ & strComputer & """ and """ & strArg & """"
End If
End If
NextSet 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
NextEnd 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
NextEnd If
NextSet 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
ElsestrMsg = strMsg & vbTab & strDrive & vbTab & "is not a writer" & vbCrLf
End If
NextWScript.Echo strMsg
intRC = arrWriters.Count
Set arrWriters = Nothing
Set arrDrives = Nothing
WScript.Quit intRC
Sub Syntax( strError )
Dim strMsgIf 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: 2025-10-11; loaded in 0.0095 seconds