Need code to detect CDRom drive letter? All Windows Versions.....

Posted on 2004-09-06
Last Modified: 2008-01-09

Good evening/morning/afternoon.

Been a while since I haev been using this site, but it has always been a great source of answers.

I am creating a batch file, and I need to be able to (using a simple line of code) to accesss the systems registry, and automatically detect the first CDRom drive letter. I would like for the batch file to automatically be able to use the info it polls frm the system. The batch file will actually be installing programs, and creatinga directory on the c drive. Where this information will be necessary, is so that it can copy from  (drive letter ) to the c:\(directory of coice).

I dont mind what kind of code is used. If it is something that can be incorporated into a DOS batch file, that would be ideal. If not I can probably change my type of setup file to some sort of self extracting file, that can execute my programs.

I look forward to the great answersr you guys will provide.
Question by:johnb6767

Expert Comment

ID: 11993985
What version of Windows are you running this batch file on? 9x/Me, 2K/XP?

Accepted Solution

wparrott earned 168 total points
ID: 11994031
This link will take you to an example using VB code:;EN-US;291575

This one uses VBA and will allow you to return the drive letter as a string:

Not exactly sure how either of these could be used in a batch file but if you want help using VB script to determine the drive letter check here:

and here:

Hope this helps...

Assisted Solution

suramsureshbabu earned 166 total points
ID: 11994360

Expert Comment

ID: 11997677
you could try this:

if exist d:\autorun.inf goto DDRIVE
if exist e:\autorun.inf goto EDRIVE
if exist f:\autorun.inf goto FDRIVE

etc, etc,.

that is, assuming you have an autorun on the cd that's in there.

Hope this helps.

Assisted Solution

DukeJ earned 166 total points
ID: 11998119
For WinNT
REM Find the CD-ROM drives and parse the strings using a subroutine
FOR /F "tokens=*" %%A IN ('TYPE %TEMP%.\CDROM1.REG ^| FIND /I "\\Device\\CdRom"') DO CALL :ParseNT4 %%A

For Win2000

SET Temp1=%Temp%.\%~n0%Random%1.reg
SET Temp2=%Temp%.\%~n0%Random%2.reg
TYPE %Temp1% > %Temp2%
TYPE %Temp2% | FIND "\\DosDevices\\" | FIND /V "\\DosDevices\\A:" | FIND "=hex:5c," > %Temp1%
FOR /F "tokens=3 delims=\:" %%A IN (%Temp1%) DO CALL :ParseW2K %%A


Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Occasionally Windows/Microsoft Updates will fail to update. We have found a code that will delete all temporary files and re-register all dll's related to Windows/Microsoft Updates! This works 99% of the time to get the updates working again! The…
I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

831 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