Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for iscdwriter.tcl

(view source code of iscdwriter.tcl as plain text)

  1. set errors 1
  2. if { $argc == 0 } {
  3.     set query "SELECT * FROM Win32_CDROMDrive"
  4.     set errors 0
  5. } elseif { $argc == 1 } {
  6.     if [regexp -nocase {^[A-Z]:$} $argv] {
  7.         set query "SELECT * FROM Win32_CDROMDrive WHERE Drive='$argv'"
  8.         set errors 0
  9.     }
  10. }
  11. if { $errors == 1 } {
  12.     puts "\nIsCDWriter.tcl,  Version 1.00"
  13.     puts "Check whether the specified drive is a CD/DVD writer or not\n"
  14.     puts "Usage:  tclsh.exe  IsCDWriter.tcl  \[ drive \]\n"
  15.     puts "Where:  drive      is the drive to be tested (default: all optical drives)\n"
  16.     puts "Note:   The script's return code equals the number of matching CD/DVD writers,"
  17.     puts "        or -1 in case of errors (including specifying a non-optical drive).\n"
  18.     puts "Written by Rob van der Woude"
  19.     puts "http://www.robvanderwoude.com"
  20.     exit -1
  21. } else {
  22.     package require twapi_wmi
  23.     namespace path twapi
  24.  
  25.     set wbem_services [comobj_object winmgmts:root/cimv2]
  26.     set colitems [$wbem_services ExecQuery $query]
  27.     set count 0
  28.  
  29.     if { [$colitems Count] == 0 } {
  30.         if { $argc == 0 } {
  31.             puts "No optical drives found"
  32.         } else {
  33.             puts "[string toupper $argv] is not even an optical drive"
  34.             set count -1
  35.         }
  36.     } else {
  37.         $colitems -iterate item {
  38.             set drive [$item Drive]
  39.             set iswriter 0
  40.             foreach c [$item Capabilities] {
  41.                 if { $c == 4 } {
  42.                     set iswriter 1
  43.                     incr count
  44.                 }
  45.             }
  46.             if { $iswriter == 1 } {
  47.                 puts "$drive is a CD/DVD writer"
  48.             } else {
  49.                 puts "$drive is NOT a CD/DVD writer"
  50.             }
  51.             $item -destroy
  52.         }
  53.     }
  54.     $colitems -destroy
  55.     $wbem_services -destroy
  56.     exit $count
  57. }

page last modified: 2024-04-16; loaded in 0.0054 seconds