[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Find Cd drives enabled

Posted on 2007-04-02
20
Medium Priority
?
133 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
ID: 18841061
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
ID: 18841311
I have removed the cable or even disabled in Bios.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18842610
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 11

Author Comment

by:bsharath
ID: 18842658
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
ID: 18842673
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
ID: 18842677
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
ID: 18842729
Where should i specify the source file and its contents
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18842901
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
ID: 18842935
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
ID: 18842951
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
 
LVL 11

Author Comment

by:bsharath
ID: 18843085
Still getting the same error
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 18843103
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
ID: 18843151
Thanks a lot this worked
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18843159
Happy to help. :^)
0
 
LVL 11

Author Comment

by:bsharath
ID: 18843238
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
ID: 18843280
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
ID: 18843321
I get the same error.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18843338
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
ID: 18843418
Thanks this worked
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18843426
:)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn more about the importance of email disclaimers with our top 10 email disclaimer DOs and DON’Ts.
This article is written by John Gates, CISSP. Gates, the SNUG President-Elect, currently holds the position of Manager of Information Systems at Lake Park High School in Roselle, Illinois.
The Bounty Board allows you to request an article or video on any technical topic, or fulfill a bounty request to earn points. Watch this video to learn how to use the Bounty Board to get the content you want, earn points, and browse submitted bount…
Where to go on the main page to find the job listings. How to apply to a job that you are interested in from the list that is featured on our Careers page.
Suggested Courses

829 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