Page 1 of 1 1
Topic Options
#185887 - 2008-03-03 05:30 PM CD in the CDROM drive
DStelz Offline
Getting the hang of it

Registered: 2007-01-26
Posts: 72
Loc: Green Bay, WI
I didn't know exactly where to post this and I didn't even know where to begin to search for this, but I was wondering if there is a way to tell if there is a CD/DVD in the drive, remotely of course. Perhaps through WMI? Any suggestions would be appreciated. I'm missing a CD and nobody knows where it is so I'm guessing I left it in a drive somewhere, but not prepared to go searching.

Thanks in advance.

Top
#185898 - 2008-03-03 09:27 PM Re: CD in the CDROM drive [Re: DStelz]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Yes WMI supports it

WIN32_CDROMDrive

Top
#185900 - 2008-03-03 09:31 PM Re: CD in the CDROM drive [Re: DStelz]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Here is some code I put together from some ideas on the list. I'm sorry, but I can't remember the exact references. You can mangle this to fit your needs. For example, if there is a disk in the drive, it will report a disk size: "The total disk space is 0.65GB" for example (if there is no disk you won't get the total disk space line).

Hope this helps,

Brad V

 Code:
;NAME		disk_info.kix
;
;DESCRIPTION	This is a script to retrieve disk information for a given computer.
;
;AUTHOR		Brad Van Orden
;
;VERSION	1.5
;
;HISTORY	Created 24 Jul 07
;		29 Aug 07 - Added a subroutine to change bytes into MBs or GBs
;
Break On
;
Dim $SO
;
; These are just programming options for me.
; One forces me to define all variables and the
; other doesn't allow a kixtart macro within a string.
;
$SO = SetOption('Explicit',          'On')
$SO = SetOption('NoMacrosInStrings', 'On')
;
DIM $strComputer, $objWMIService, $colDisks, $objDisk, $arrDisk[4,0]
DIM $intCount, $strFile, $intErr, $strType, $strSiz
;
$strComputer = "."
While $strComputer == "."
   ? "Please enter the name of the workstation:"
   Gets $strComputer
Loop
; Make sure no leading or trailing spaces were accidently added to the name.
;
$strComputer = Trim($strComputer)
;
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
If @ERROR <> 0
   ? "Could not map to the Windows Management Instrumentation object for computer, " + $strComputer
   exit 1
Else
   $strFile  = "C:\Documents and Settings\" + @userid + "\Desktop\" + $strComputer + "_disk_info.ini"
   $intCount = 0
   $colDisks = $objWMIService.ExecQuery("Select * FROM Win32_LogicalDisk")
   For Each $objDisk in $colDisks
      ReDim Preserve $arrDisk[4,$intCount]
      Select
         Case $objDisk.DriveType = "2"
            $arrDisk[0,$intCount] = "This device is a floppy drive."
            $strType = "Floppy Drive"
         Case $objDisk.DriveType = "3"
            $arrDisk[0,$intCount] = "This device is a hard drive."
            $strType = "Hard Drive"
         Case $objDisk.DriveType = "4"
            $arrDisk[0,$intCount] = "This device is a mapped network drive."
            $strType = "Mapped Network Drive" + $intCount
         Case $objDisk.DriveType = "5"
            $arrDisk[0,$intCount] = "This device is a CD or DVD drive."
            $strType = "CD/DVD Drive"
         Case 1
            $arrDisk[0,$intCount] = "Note sure what this device type is: " + $objDisk.DriveType
            $strType = "Unknown"
      EndSelect
      $arrDisk[1,$intCount] = $objDisk.DeviceID
      $arrDisk[2,$intCount] = $objDisk.FileSystem
      $arrDisk[3,$intCount] = $objDisk.FreeSpace
      $arrDisk[4,$intCount] = $objDisk.Size
      If $objDisk.DriveType <> "4"
         ? "This device type is " + $strType
         ? "The drive letter of this device is " + $arrDisk[1,$intCount]
         $intErr = WriteProfileString($strFile,$strType,"Device ID",$arrDisk[1,$intCount])
         If $arrDisk[2,$intCount] <> ""
            ? "The file system type is " + $arrDisk[2,$intCount]
         EndIf
         $intErr = WriteProfileString($strFile,$strType,"File System Type",$arrDisk[2,$intCount])
         If $arrDisk[3,$intCount] <> ""
            $strSiz = Join(MagQ($arrDisk[3,$intCount]),"")
            ? "The amount of free space on this disk is " + $strSiz
         EndIf
         $intErr = WriteProfileString($strFile,$strType,"Free Space",$strSiz)
         If $arrDisk[4,$intCount] <> ""
            $strSiz = Join(MagQ($arrDisk[4,$intCount]),"")
            ? "The total disk space is " + $strSiz

         EndIf
         $intErr = WriteProfileString($strFile,$strType,"Disk Size",$strSiz)
      EndIf
      $intCount = $intCount + 1
      $strSiz   = ""
   Next
EndIf
Sleep 5
;
;Function:	MagQ()
;
;Author:	Brad Van Orden
;
;Version:	1.0
;
;History	Created 23 Aug 07
;
;Action:	Takes in a number and returns it quantified to the appropriate magnitude prefix.
;
;Syntax:	MagQ($intSize)
;
;Parameters:	intSize - The number we wish to quantify.
;
;Returns:	Two-dimensional array as follows:
;		0 - Computed Size
;		1 - Size Prefix
;
Function MagQ($intSize)
   ;
   Dim $arrRes[1], $GIGA, $MEGA, $KILO
   ;
   $KILO = 1024.
   $MEGA = $KILO * $KILO
   $GIGA = $MEGA * $KILO
   ;
   Select
      Case $intSize > $GIGA
         $arrRes[0] = (1. * CINT((CDBL($intSize)/$GIGA)*100))/100.
         $arrRes[1] = "GB"
      Case $intSize > $MEGA
         $arrRes[0] = (1. * CINT((CDBL($intSize)/$MEGA)*100))/100.
         $arrRes[1] = "MB"
      Case $intSize > $KILO
         $arrRes[0] = (1. * CINT((CDBL($intSize)/$KILO)*100))/100.
         $arrRes[1] = "KB"
   EndSelect
   $MagQ = $arrRes
EndFunction

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.278 seconds in which 0.054 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org