Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbs Script yes/no Cd-rom output

Status
Not open for further replies.

Aaroui

IS-IT--Management
May 17, 2013
4
Hi guys,

I am new here and also new to scripting.
I am searching for a script that determines whether there is a Cd-rom or not
Currently I have this:

Code:
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_CDROMDrive")
For Each objItem in colItems
cdrom= objItem.Drive & ";"
next

now it shows the drive letter if present. but what I want is a way that the script will write down yes or no if the Cd-rom drive is present or not present.

Can anybody please help me with this?
 
well what you have won't work because you havent't defined [tt]objWMIService[/tt]

Code:
[COLOR=#CC0000]strComputerName = "."
set objWMIService  = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")[/color]

Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
   cdrom= objItem.Drive & ";"
next 

[COLOR=#CC0000]if (cdrom <> null) then
   msgbox "Your CD-ROM drive is " & cdrom
else
   msgbox "You have no CD-ROM"
end if[/color]

-Geates

 
Thank you for your post.

Actually I have defined objWMIService but this is just a part of my whole script.
I think your script is not correct, If I run it on my Computer it says You have no CD-ROM as I have a CD-ROM drive this is not correct.
So what I'm searching for is something to ad to that part of my script that shows up yes or no in place of the Drive letter.
 
Yes, my script was giving me my drive letter. but yours said You "have no CD-ROM" I have changed your script to:

Code:
For Each objItem in colItems
cdrom= objItem.Drive & ";"
next
if (cdrom <> null) then
  cdrom= "No"
else
  cdrom= "Yes"
end if

The part I do not understand is where you type "<> null" I am testing it right now, so I dont know what it's going to do I'll let you know
 
I have tested it and it just says yes whether there is a CD-rom drive or not.
 
Isn't that what you're requesting?

[tt]if (cdrom <> null) then[/tt] is testing the contents of "cdrom". In pseudo-code, it would read, "if cdrom is not null(nothing) then". To begin, [tt]cdrom[/tt] is null because it hasn't been defined yet. If there were items in colItems, then the for each loop would have executed and [tt]cdrom[/tt] would be assigned something other than null.

-Geates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top