set errors 1 if { $argc == 0 } { set query "SELECT * FROM Win32_CDROMDrive" set errors 0 } elseif { $argc == 1 } { if [regexp -nocase {^[A-Z]:$} $argv] { set query "SELECT * FROM Win32_CDROMDrive WHERE Drive='$argv'" set errors 0 } } if { $errors == 1 } { puts "\nIsCDWriter.tcl, Version 1.00" puts "Check whether the specified drive is a CD/DVD writer or not\n" puts "Usage: tclsh.exe IsCDWriter.tcl \[ drive \]\n" puts "Where: drive is the drive to be tested (default: all optical drives)\n" puts "Note: The script's return code equals the number of matching CD/DVD writers," puts " or -1 in case of errors (including specifying a non-optical drive).\n" puts "Written by Rob van der Woude" puts "http://www.robvanderwoude.com" exit -1 } else { package require twapi_wmi namespace path twapi set wbem_services [comobj_object winmgmts:root/cimv2] set colitems [$wbem_services ExecQuery $query] set count 0 if { [$colitems Count] == 0 } { if { $argc == 0 } { puts "No optical drives found" } else { puts "[string toupper $argv] is not even an optical drive" set count -1 } } else { $colitems -iterate item { set drive [$item Drive] set iswriter 0 foreach c [$item Capabilities] { if { $c == 4 } { set iswriter 1 incr count } } if { $iswriter == 1 } { puts "$drive is a CD/DVD writer" } else { puts "$drive is NOT a CD/DVD writer" } $item -destroy } } $colitems -destroy $wbem_services -destroy exit $count }