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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make VBScript detect CD-Rom Drive and Install Software from it?

Status
Not open for further replies.

Ludacris

Technical User
Jun 19, 2004
9
US
Hello! I am new to VBScript and was hoping to get some help from some of you guys. Basically, I 'd like to setup a vbscript that asks/or auto-detects your CD-Rom drive or Thumb Drive so that I can install some software in a particular order. Can any of you guys help me?

 
Hello Ludacris,

You can try something like this.
Code:
dim aDrive()
bRet=getCDRomDrive(aDrive)
if bRet then
	wscript.echo "No of CDRomDrive : " & ubound(aDrive)+1
	for i=0 to ubound(aDrive)
		wscript.echo "CDRomDrive #" & i & " : " & aDrive(i)
	next
else
	wscript.echo "No CDRomDrive installed."
end if

function getCDRomDrive(byRef aDrv)
	set svc=getobject("winmgmts:root\cimv2")
	sQuery="select * from win32_cdromdrive"
	set ccdrom=svc.execquery(sQuery)
	if ccdrom.count>=0 then
		erase aDrv
		redim aDrv(ccdrom.count-1)
		getCDRomDrive=true
		i=0
		for each ocdrom in ccdrom
			aDrv(i)=ocdrom.drive
			i=i+1
		next
	else
		getCDRomDrive=false
	end if
	set ccdrom=nothing : set svc=nothing
end function
regards - tsuji
 
Thank you kind Sir! I appreciate your help and I will report back here after I have have completed work on my script.
 
Ludacris,

As I was passing array, it may be more involved in thinking clear once problem arises. I would therefore propose an easier version of passing a delimited string as the [out] parameter which would be easier to debug.
Code:
dim delimiter, sep, sDrives, aDrives, i
delimiter=";"
bRet=getCDRomDrive_alt(sDrives, delimiter)
if bRet then
    if delimiter="" then sep=";" else sep=delimiter
    aDrive=split(sDrives,sep)
    wscript.echo "No of CDRomDrive : " & ubound(aDrive)+1
    for i=0 to ubound(aDrive)
        wscript.echo "CDRomDrive #" & i & " : " & aDrive(i)
    next
else
    wscript.echo "No CDRomDrive installed."
end if

function getCDRomDrive_alt(sDrv, delimiter)
    dim svc, ccdrom, ocdrom, sep, i
    dim aDrv()
    set svc=getobject("winmgmts:root\cimv2")
    sQuery="select * from win32_cdromdrive"
    set ccdrom=svc.execquery(sQuery)
    if ccdrom.count>=0 then
        redim aDrv(ccdrom.count-1)
        getCDRomDrive_alt=true
        i=0
        for each ocdrom in ccdrom
            aDrv(i)=ocdrom.drive
            i=i+1
        next
        'default to ";" as delimiter
        if delimiter="" then sep=";" else sep=delimiter
        sDrv=join(aDrv,sep)
    else
        getCDRomDrive_alt=false
    end if
    set ccdrom=nothing : set svc=nothing
end function
- tsuji
 
Thanks again Sir. I just got back in from a business trip and will attempt to work on the code this weekend. I will report back my progress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top