Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Find Cd drives enabled

Hi,

As my company does not allow cd drives to be enabled so i need a script or tool to find which all machines that have Cd drives ENABLE.

Regards
sharath
Avatar of sirbounty
sirbounty
Flag of United States of America image

What do you mean by enabled?
Are they stopped simply via policy or have you shut them down some other way?
Avatar of bsharath

ASKER

I have removed the cable or even disabled in Bios.
Ah, I see...something like this should tell you then...

Dim objNet:Set objNet=CreateOjbect("Wscript.Network")
Dim objWMI:Set objWMI=GetObject("winmgmts:\\.\root\CIMV2")
Dim colROM:Set colROM=objWMI.ExecQuery("Select & From Win32_LogicalDisk Where MediaType=11") 'MediaType 11 is a CD-ROM
If colROM.Count > 0 Then wscript.echo objNet.ComputerName & " has an enabled CD-ROM".

What you do with this is still 'open'...how are you wanting to poll these devices.  The above would run it on a per-machine basis, but you didn't specify any reporting mechanism.
You could run it in a login script and have it silently report back to a central file...would that work?
Can we give a list of machine names from which it can scan the machines and report to a file instead of GP.

THX
Sharath
Absolutely! Here's a full reporting script - just modify the source file as needed...
Format the file like:
Computer1
Computer2
[...etc...] making sure there's a carriage return <Enter> after each computer name...


'FindCDRoms.vbs
Dim objWMI, colROM
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objOutput: Set objOutput=objFSO.CreateTextFile("C:\CD-Rom_Report.txt")
arrPCs=Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
For Each PC in arrPCs
  Set objWMI=GetObject("winmgmts:\\" & PC & "\root\CIMV2")
  Set colROM=objWMI.ExecQuery("Select & From Win32_LogicalDisk Where MediaType=11") 'MediaType 11 is a CD-ROM
  If colROM.Count > 0 Then objOutput.WriteLine PC & " has an enabled CD-ROM".
Next
objOutput.Close
Set objOutput=Nothing
Set objWMI=Nothing
Set objFSO=Nothing
Set colRom=Nothing
Admittedly, that's untested - so if you find any type-o errors, let me know the line number they're on...
Where should i specify the source file and its contents
There's the first type-o, eh?  Hopefully the last...here's the updated:

'FindCDRoms.vbs
Dim objWMI, colROM
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objOutput: Set objOutput=objFSO.CreateTextFile("C:\CD-Rom_Report.txt")
SourceFile="C:\Computers.txt"
arrPCs=Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
For Each PC in arrPCs
  Set objWMI=GetObject("winmgmts:\\" & PC & "\root\CIMV2")
  Set colROM=objWMI.ExecQuery("Select & From Win32_LogicalDisk Where MediaType=11") 'MediaType 11 is a CD-ROM
  If colROM.Count > 0 Then objOutput.WriteLine PC & " has an enabled CD-ROM".
Next
objOutput.Close
Set objOutput=Nothing
Set objWMI=Nothing
Set objFSO=Nothing
Set colRom=Nothing
Error
C:\>cscript abc.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\abc.vbs(9, 78) Microsoft VBScript compilation error: Expected identifier
Line 9: Set colROM=objWMI.ExecQuery("Select & From Win32_LogicalDisk Where MediaType=11")

Should read:
Set colROM=objWMI.ExecQuery("Select * From Win32_LogicalDisk Where MediaType=11")

'Changed the & to a *
Still getting the same error
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot this worked
Happy to help. :^)
Sorry Sirbounty i get this error when it does not find a machine or machine switched off.

C:\>cscript abc.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\abc.vbs(7, 3) Microsoft VBScript runtime error: The remote server machine doe
s not exist or is unavailable: 'GetObject'
You'll need to skip those then...use this:

'FindCDRoms.vbs
On Error Resume Next
Dim objWMI, colROM
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\CD-Rom_Report.txt")
SourceFile = "C:\Computers.txt"
arrPCs = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
For Each PC In arrPCs
  Set objWMI = GetObject("winmgmts:\\" & PC & "\root\CIMV2")
  If Err.Number = 0 Then
    Set colROM = objWMI.ExecQuery("Select * From Win32_LogicalDisk Where MediaType=11") 'MediaType 11 is a CD-ROM
    If colROM.Count > 0 Then objOutput.WriteLine PC & " has an enabled CD-ROM"
  End If
  On Error Goto 0
Next
objOutput.Close
Set objOutput = Nothing
Set objWMI = Nothing
Set objFSO = Nothing
Set colROM = Nothing
I get the same error.
Try this version....

'FindCDRoms.vbs
Dim objWMI, colROM
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\CD-Rom_Report.txt")
SourceFile = "C:\Computers.txt"
arrPCs = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
For Each PC In arrPCs
  On Error Resume Next
  Set objWMI = GetObject("winmgmts:\\" & PC & "\root\CIMV2")
  If Err.Number = 0 Then
    Set colROM = objWMI.ExecQuery("Select * From Win32_LogicalDisk Where MediaType=11") 'MediaType 11 is a CD-ROM
    If colROM.Count > 0 Then objOutput.WriteLine PC & " has an enabled CD-ROM"
  End If
  On Error Goto 0
Next
objOutput.Close
Set objOutput = Nothing
Set objWMI = Nothing
Set objFSO = Nothing
Set colROM = Nothing
Thanks this worked