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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
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.

733 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