Solved

Find Cd drives enabled

Posted on 2007-04-02
20
115 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Gift cards are not a new concept - it's been around for a very long time.  Undoubtedly, over the past you have received such a card or purchased one for a friend or relative.  Are you aware that you've been feeding the machine?  If not, read on :)
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…
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.

770 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