bsharath
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
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
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("Wscri pt.Network ")
Dim objWMI:Set objWMI=GetObject("winmgmts :\\.\root\ CIMV2")
Dim colROM:Set colROM=objWMI.ExecQuery("S elect & 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?
Dim objNet:Set objNet=CreateOjbect("Wscri
Dim objWMI:Set objWMI=GetObject("winmgmts
Dim colROM:Set colROM=objWMI.ExecQuery("S
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?
ASKER
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
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("Scrip ting.FileS ystemObjec t")
Dim objOutput: Set objOutput=objFSO.CreateTex tFile("C:\ CD-Rom_Rep ort.txt")
arrPCs=Split(objFSO.OpenTe xtFile(Sou rceFile).R eadAll, vbNewLine)
For Each PC in arrPCs
Set objWMI=GetObject("winmgmts :\\" & PC & "\root\CIMV2")
Set colROM=objWMI.ExecQuery("S elect & 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
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("Scrip
Dim objOutput: Set objOutput=objFSO.CreateTex
arrPCs=Split(objFSO.OpenTe
For Each PC in arrPCs
Set objWMI=GetObject("winmgmts
Set colROM=objWMI.ExecQuery("S
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...
ASKER
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("Scrip ting.FileS ystemObjec t")
Dim objOutput: Set objOutput=objFSO.CreateTex tFile("C:\ CD-Rom_Rep ort.txt")
SourceFile="C:\Computers.t xt"
arrPCs=Split(objFSO.OpenTe xtFile(Sou rceFile).R eadAll, vbNewLine)
For Each PC in arrPCs
Set objWMI=GetObject("winmgmts :\\" & PC & "\root\CIMV2")
Set colROM=objWMI.ExecQuery("S elect & 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
'FindCDRoms.vbs
Dim objWMI, colROM
Dim objFSO:Set objFSO=CreateObject("Scrip
Dim objOutput: Set objOutput=objFSO.CreateTex
SourceFile="C:\Computers.t
arrPCs=Split(objFSO.OpenTe
For Each PC in arrPCs
Set objWMI=GetObject("winmgmts
Set colROM=objWMI.ExecQuery("S
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
ASKER
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
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("S elect & From Win32_LogicalDisk Where MediaType=11")
Should read:
Set colROM=objWMI.ExecQuery("S elect * From Win32_LogicalDisk Where MediaType=11")
'Changed the & to a *
Should read:
Set colROM=objWMI.ExecQuery("S
'Changed the & to a *
ASKER
Still getting the same error
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot this worked
Happy to help. :^)
ASKER
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'
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.Fi leSystemOb ject")
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\ CD-Rom_Rep ort.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
'FindCDRoms.vbs
On Error Resume Next
Dim objWMI, colROM
Dim objFSO: Set objFSO = CreateObject("Scripting.Fi
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\
SourceFile = "C:\Computers.txt"
arrPCs = Split(objFSO.OpenTextFile(
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
ASKER
I get the same error.
Try this version....
'FindCDRoms.vbs
Dim objWMI, colROM
Dim objFSO: Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\ CD-Rom_Rep ort.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
'FindCDRoms.vbs
Dim objWMI, colROM
Dim objFSO: Set objFSO = CreateObject("Scripting.Fi
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\
SourceFile = "C:\Computers.txt"
arrPCs = Split(objFSO.OpenTextFile(
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
ASKER
Thanks this worked
:)
Are they stopped simply via policy or have you shut them down some other way?