Jump to content

Determine if CD-R drive exists


Recommended Posts


Well, using WMI might hold some promise. According to this documentation, the "Capabilities" attribute might work. If a drive supports writing, it will show that.

http://msdn.microsoft.com/library/default...._cdromdrive.asp

So, if you don't mind doing a little VBScripting or JavaScripting you could check the capabilities of any CD drives and install the buring software on any that support writing.

Link to comment
Share on other sites

Here a script that will tell if it a CD-RW

Check_For_CDRW.VBS

On Error Resume Next

Dim Act, SearchString, SearchChar, MyPos

strComputer = "."

Set Act = CreateObject("Wscript.Shell")

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")

For Each objItem in colItems

SearchString = objItem.Caption

MyPos = Instr(1, SearchString, "RW")

If MyPos = 1 Then

MsgBox "This Is Not A CD-RW", 0 + 32, "Not A CD-RW"

Else

SearchChar = "Caption: " & objItem.Caption & vbCrLf & "Name: " & objItem.Name & vbCrLf

MsgBox SearchChar, 0 + 32, "Confirm CD-RW"

'''''PLACE THE SOFTWARE INSTALL PART BELOW HERE

'''''PLACE QUOTE AROUND THE PATH AND SWITCHES "PATH_TO_SOFTWARE /SWITCHES"

''Act.Run(PLACE_THE_SOFTWARE_TO_INSTALL_HERE),1,True

'''''END THE SOFTWARE INSTALL HERE

Exit For

End If

Next

Here is a script that checks for CD drives

Dim Act,CD,Fso

Set Act = CreateObject("Wscript.Shell")

Set Fso = CreateObject("Scripting.FileSystemObject")

Set CD = Fso.Drives

For Each strCd In CD

If strCd.DriveType = 4 Then

Act.Popup strCd, 5,"CDROM", 0 + 32

End If

Next

Link to comment
Share on other sites

Thanks for both of your replies. I wrote the following script the to check for a CD-R drive but it isn't working:

ReturnCode=0
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colCDROMDrive = objWMIService.ExecQuery ("Select * from Win32_CDROMDrive")

For each objCDROMDrive in colCDROMDrive
For i = 0 to Ubound(objCDROMDrive.Capabilities)
' Wscript.Echo "CDROMDrive Capabilities: " & objCDROMDrive.Capabilities(i)
if objCDROMDrive.Capabilities(i) = 4 then ReturnCode = 1
Next
Next

'Wscript.Echo "Return Code: " & ReturnCode
Wscript.Quit(ReturnCode)

I am getting capabilities of 3 and 7 for a drive Windows recognizes as a CD-RW drive. I am hesitant to use the Caption property unless there is a documented industry-wide naming convention.

Link to comment
Share on other sites

@Dear GSM

Script has some problem in correctly detecting CD-RW drive. In my machine script just checks my CD-ROM drive and not the CD-RW drive, and then exits. Although if I manually run WMI code (without the Check_For_CDRW.VBS) to get "Caption" feedbacks, it correctly detects Caption for both the drives.

@Bezalel

Please check http://www.msfn.org/board/index.php?showtopic=49226&st=0 where Martin Zugec described PnP-based Software installation method. He suggests Nero installation on the basis of detecting PnPDeviceId for your CD-RW hardware. His script indeed has section about Nero installation, if i can remember correctly.

P.S. "Capabilities" property checking will not help you as correct implementation of it inside a script depends upon the inheritance of this property from CIM_MediaAccessDevice which is still not implementable. That's why you're not getting Value = 4 as you expected.

For the time being just check Martin's script and modify as per your need. Post after you finished checking and after you learnt the pros-&-cons of that script. Only then I'll help you into the more attractive realms of WMI-guided world of software installation. I'll be glad if after applying his script you start posting there, in his thread, as only then you'll enter the zone of other software installations apart from this CD-RW drive -based Nero installation. Both Martin and me are interested in taking PnP Device Detection based software installation to a meaningfull stage. I hope you're helped.

Link to comment
Share on other sites

I've been using WMI in vbs for quite some time now for a number of tasks. Unfortunately detecting hardware capabilities and properties is something where you are often at the mercy of the hardware vendor. It seems optional as to whether or not they implement proper reporting. BIOS strings are a famous example of this.

Link to comment
Share on other sites

I was searching through the registry to determine where the drive information is kept. I finally found this article Q316529 that mentions that the keys are under HKEY_CURRENT_USER. The really weird thing is that the registry identifies the drive as a CD-R drive and Explorer identifies it as a CD-RW drive.

Link to comment
Share on other sites

  • 3 weeks later...

Is it possible to use this script with diskpart? I need to change my cd to R: (is e: right after install, d: is a zip drive) and make another partition that is e:.

Right now I call a bat with command.txt that runs diskpart script that

selects volume 0 (the cd)

removes drive letter (it has the e: and I need to create a partition with e:)

assign r:

create my partition with e: letter.

I need a more reliable method of getting the cd drive letter. I tried another method (mapdrive.cmd) that is heavily commented but couldn't get it to work, maybe due to me doing this on w2k.

Thanks,

Link to comment
Share on other sites

this script will give you a list of CDRom drives and their drive letters.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colCDROMDrive = objWMIService.ExecQuery ("Select * from Win32_CDROMDrive")

For each objCDROMDrive in colCDROMDrive
Wscript.Echo objCDROMDrive.Drive & " " & objCDROMDrive.Caption
Next

Link to comment
Share on other sites

Looks like I am going to have to figure out this scripting, I am not sure where to paste this or how to pass this to diskpart. I am a newbie at batchs in windows. (I can sometimes figure out DOS :) )

I need to figure out the diff of cmd, bat and scripts (scr?). Can I use this syntax in a bat called from command.txt? How do I pass it to diskpart?

Thanks for your reply! Sorry for the newbie questions...

Link to comment
Share on other sites

I developed same util before.

Usage

test.exe [options] filename

Options:

/CDR check CD writer

/DVD check DVD reader

/DVR check DVD writer

for example

test.exe /CDR /DVD myapp.exe will run myapp.exe only both CD writing and DVD reading capability exist otherwise it will simply exit.When it starts program, it waits until new spawned process ends.Order of options is not important, unrecognized parameters will be ignored but filename must be the last parameter.

testcd.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...