Script to find if there is a R/W drive installed

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
BridgeScore
Newbie
Posts: 14
Joined: Sun Feb 26, 2006 3:55 pm
Location: Florida
Contact:

Script to find if there is a R/W drive installed

Post by BridgeScore » Wed Mar 08, 2006 4:53 am

I found this VBSCRIPT to test for CD R/W drives on a system. How can I run this in MS 8.01? I am not sure how to call this and get the results. I realize that this is a sort of hack and may not work to find the drives all the time. Thanks.


vbstart
'--------------------8 0 Or _
InStr(sDevID, "-RW") > 0 Or _
InStr(sName, "-RW") > 0 Or _
InStr(sCaption, "-R ") > 0 Or _
InStr(sDevID, "-R ") > 0 Or _
InStr(sName, "-R ") > 0 Or _
InStr(sCaption, "-R/RW") > 0 Or _
InStr(sDevID, "-R/RW") > 0 Or _
InStr(sName, "-R/RW") > 0 Then
sDrive = oItem.Drive
Exit For ' exit loop after first hit
End If
Next


If IsEmpty(sDrive) Then
WScript.Echo "No writable CD/DVD drive found"
Else
WScript.Echo "Likely writable CD/DVD drive found, drive letter is " & sDrive
End If
'--------------------8???
___________________________________
Writing the program is easy
finishing the program is hard

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Mar 08, 2006 9:18 am

Here you go:

VBSTART
Function GetRWDrives

sComputer = "." ' use "-." for local computer
Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set colItems = oWMIService.ExecQuery("Select * from Win32_CDROMDrive")

For Each oItem in colItems
sCaption = UCase(oItem.Caption)
sDevID = UCase(oItem.DeviceID)
sName = UCase(oItem.Name)

If InStr(sCaption, "-RW") > 0 Or _
InStr(sDevID, "-RW") > 0 Or _
InStr(sName, "-RW") > 0 Or _
InStr(sCaption, "-R ") > 0 Or _
InStr(sDevID, "-R ") > 0 Or _
InStr(sName, "-R ") > 0 Or _
InStr(sCaption, "-R/RW") > 0 Or _
InStr(sDevID, "-R/RW") > 0 Or _
InStr(sName, "-R/RW") > 0 Then
sDrive = oItem.Drive
Exit For ' exit loop after first hit
End If
Next

If IsEmpty(sDrive) Then
sDrive = "NONE"
End If

GetRWDrives = sDrive
End Function
VBEND

VBEval>GetRWDrives,s
MessageModal>RW Drive: %s%

It didn't work with my RW Drive. The way this works is it looks to see if it can see any combination of -RW in the drive's name, device ID or caption. Mine doesn't. Mine does have the text "RW" in it but not preceeded by a hyphen. So it works for me if I modify the code thus:

VBSTART
Function GetRWDrives

sComputer = "." ' use "-." for local computer
Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set colItems = oWMIService.ExecQuery("Select * from Win32_CDROMDrive")

For Each oItem in colItems
sCaption = UCase(oItem.Caption)
sDevID = UCase(oItem.DeviceID)
sName = UCase(oItem.Name)

If InStr(sCaption, "-RW") > 0 Or _
InStr(sDevID, "-RW") > 0 Or _
InStr(sName, "-RW") > 0 Or _
InStr(sCaption, "-R ") > 0 Or _
InStr(sDevID, "-R ") > 0 Or _
InStr(sName, "-R ") > 0 Or _
InStr(sCaption, "-R/RW") > 0 Or _
InStr(sDevID, "-R/RW") > 0 Or _
InStr(sName, "-R/RW") > 0 Or _
InStr(sName, "RW") > 0 Or _
InStr(sCaption, "RW") > 0 Or _
InStr(sDevID, "RW") > 0 Then
sDrive = oItem.Drive
Exit For ' exit loop after first hit
End If
Next

If IsEmpty(sDrive) Then
sDrive = "NONE"
End If

GetRWDrives = sDrive
End Function
VBEND

VBEval>GetRWDrives,s
MessageModal>RW Drive: %s%

However, the problem with this is that RW could appear in a drive name that is not a CD R/W drive.

In short, I wouldn't rely on this at all!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

BridgeScore
Newbie
Posts: 14
Joined: Sun Feb 26, 2006 3:55 pm
Location: Florida
Contact:

Post by BridgeScore » Wed Mar 08, 2006 2:32 pm

Did not find my RW drive either. Some of the people using my macro have never burned a CD and have no idea if they have one or not. I have a utility that can burn CD's that I can use as in a dos command window but I would like to be able to find the burner on their systems.

Funny thing is there must be a way. Whenever I have installed any burner software package. It always seems to be able to tell which of my drives is the burner and which should be the source drive. If I have two RW drives they provide a drop down box allowing the choice of either.

So how do they find the drives???
___________________________________
Writing the program is easy
finishing the program is hard

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts