Solved

Find Cd drives enabled

Posted on 2007-04-02
20
108 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:bsharath
  • 11
  • 9
20 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
What do you mean by enabled?
Are they stopped simply via policy or have you shut them down some other way?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I have removed the cable or even disabled in Bios.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
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
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Admittedly, that's untested - so if you find any type-o errors, let me know the line number they're on...
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Where should i specify the source file and its contents
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
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
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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 *
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Author Comment

by:bsharath
Comment Utility
Still getting the same error
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
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
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Thanks a lot this worked
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Happy to help. :^)
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
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'
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get the same error.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Thanks this worked
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
:)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows 10 Updates - Best Practice 16 107
searching on website for specific words/phrases 9 71
HD to RCA 7 89
Graph function 4 53
Stuck in voice control mode on your Amazon Firestick?  Here is how to turn it off!!!
This story has been written with permission from the scammed victim, a valued client of mine – identity protected by request.
Articles on a wide range of technology and professional topics are available on Experts Exchange. These resources are written by members, for members, and can be written about any topic you feel passionate about. Learn how to best write an article t…
Saved searches can save you time by quickly referencing commonly searched terms on any topic. Whether you are looking for questions you can answer or hoping to learn about a specific issue, a saved search can help you get the most out of your time o…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now