Identifying the CDROM drive letter - two methods?

Questions about Update Pack making? Ask here.
Post Reply
User avatar
SymSpaceT
Posts: 114
Joined: Thu Jan 24, 2008 5:56 pm

Identifying the CDROM drive letter - two methods?

Post by SymSpaceT » Tue Aug 04, 2009 6:45 am

Hello folks,

As a noob, I have to fight my way through every little painstaking detail. This one is identifying the CDROM drive letter during installation.

I have searched this and the MSFN site and there seems to be two methods and I have questions regarding both.

The first is a method I found is from a posted code by the user "CrashFly". I am not sure if this is actually a CDROM identification, that is my first question.

Code: Select all

cWnd /hide @
@echo off
SetLocal enableextensions
SET CDROM=%~d0

The second method is the standard method (or so it seems to me):

Code: Select all

FOR %%i IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\win51 SET CDROM=%%i:

Questions:

1. Did I actually identify the first method correctly as setting the CDROM variable to the drive's actual letter?
If it is, could somebody explain how (why) it works? (it seems cryptic to me).

2. The second method seem to do a search for a "win51" directory (?) in the root of the drive. Is this correct? Or is it the "name" of the CD? I neither have that name nor that directory on my CD - do I need to modify this tag to something I have, like the standard I386 (if it is a directory in the search)?

Thanks:

SST
Last edited by SymSpaceT on Tue Aug 04, 2009 12:18 pm, edited 1 time in total.

User avatar
SymSpaceT
Posts: 114
Joined: Thu Jan 24, 2008 5:56 pm

Post by SymSpaceT » Tue Aug 04, 2009 8:54 am

I apologize, I just found the answer:


http://unattended.msfn.org/unattended.xp/view/web/59/


SST

User avatar
ricktendo64
Posts: 3213
Joined: Mon May 22, 2006 12:27 am
Location: Honduras

Post by ricktendo64 » Tue Aug 04, 2009 12:01 pm

1 is much much better, thanks did not know there was an easier one

User avatar
mr_smartepants
Posts: 824
Joined: Thu May 18, 2006 5:56 am
Location: Cambridgeshire, UK

Post by mr_smartepants » Tue Aug 04, 2009 2:39 pm

I didn't know about 1 either! I'll try it out!
Image
Some heroes don't wear capes, they wear Kevlar and dog-tags!

User avatar
crashfly
Posts: 789
Joined: Thu Mar 13, 2008 11:39 pm
Location: Arkansas, USA

Post by crashfly » Tue Aug 04, 2009 2:43 pm

For notes on the "first" method, it works by taking the drive letter of the script where it is run from. So "technically" you can make the script think the cdrom drive is *any* drive by running the script on *that* drive.

Enabling the 'local extensions' just allows for the variable string manipulation to work.
A mind is like a parachute, it only functions when it is open.
--Anonymous

How to Ask Questions the Smart Way

User avatar
SymSpaceT
Posts: 114
Joined: Thu Jan 24, 2008 5:56 pm

Post by SymSpaceT » Wed Aug 05, 2009 10:26 am

NOTE:

1. The code for the first method posted in the first post is incomplete; read description at the link in the second post.

2. The second method is prone to the (unlikely) situation when a drive other than the CDROM has the same tagfile on it; in this case.... I don't know what will happen.


SST

P.S.: I guess it's useful to have some noobs around... they bound to think of things you never thought of.

User avatar
crashfly
Posts: 789
Joined: Thu Mar 13, 2008 11:39 pm
Location: Arkansas, USA

Post by crashfly » Wed Aug 05, 2009 12:22 pm

SymSpaceT wrote: 1. The code for the first method posted in the first post is incomplete; read description at the link in the second post.
Not really incomplete. The link specifies "requiring" the command 'Endlocal', but it is not required. All you are doing is turning on the 'extensions', but when the batch file ends, so do the 'extensions'. Therefore it is not incomplete because the command is not required.
A mind is like a parachute, it only functions when it is open.
--Anonymous

How to Ask Questions the Smart Way

Chilltownnj
Posts: 9
Joined: Sat Aug 02, 2008 7:41 pm
Location: Jersey City N.J.

This has worked for me by itself

Post by Chilltownnj » Wed Aug 26, 2009 11:47 pm

SET CDROM=%~d0

I Have been using that command with my batch scripts for a while, so far it works without even setting

cWnd /hide @ (usually throws up a "is not recognized as an internal or external command)

SetLocal enableextensions

Am i missing something? Is it necessary in runonce or cmdlines.txt ?

User avatar
yumeyao
Moderator
Posts: 1718
Joined: Sun Aug 27, 2006 9:24 pm
Location: Taiyuan, Shanxi, PR China

Post by yumeyao » Wed Aug 26, 2009 11:55 pm

I think "SET CDROM=%~d0" equals to "SET CDROM=%cd:~0,1%", they all return current driver letter.
Image
My work list(Hosted by dumpydooby)

User avatar
crashfly
Posts: 789
Joined: Thu Mar 13, 2008 11:39 pm
Location: Arkansas, USA

Re: This has worked for me by itself

Post by crashfly » Thu Aug 27, 2009 2:13 pm

Chilltownnj wrote:SET CDROM=%~d0

I Have been using that command with my batch scripts for a while, so far it works without even setting

cWnd /hide @ (usually throws up a "is not recognized as an internal or external command)

SetLocal enableextensions

Am i missing something? Is it necessary in runonce or cmdlines.txt ?
The "cWnd" command is a program that hides the dos box that shows when running most batch files. The "set CDROM" command is necessary only if you have items that get run from the CDROM during 'RunOnce' or 'RunOnceEx'. The "SetLocal" command may sometimes be necessary if the batch file extensions were ever turned off. Your mileage may vary with that.
A mind is like a parachute, it only functions when it is open.
--Anonymous

How to Ask Questions the Smart Way

User avatar
dumpydooby
Posts: 530
Joined: Sun Jan 15, 2006 6:09 am

Post by dumpydooby » Fri Aug 28, 2009 5:28 am

First one works by defining %cdrom% as the drive letter of the path in which the current script resides.

I prefer the second method myself, actually, because I'm often instantiating the script from %SystemDrive% but I'm calling files on the disc.

Kurt_Aust
Posts: 96
Joined: Fri Jul 25, 2008 6:23 pm
Location: Sydney, Australia

Post by Kurt_Aust » Sat Aug 29, 2009 1:46 am

OK, so it's kind of dated, but for compatibility with Windows 2000 when using the second method one should count backwards. The reason being that if one has a card reader it will hit it and throw a device not ready error before it hits the optical drives.

For example to call a script (batch file on CD):

Code: Select all

For %%I in (Z Y X W V U T S R Q P O N M L K J I H G F E D) do CMD /R "%%I:\Script.bat %%I"
OR (batch file on HDD):

Code: Select all

For %%I in (Z Y X W V U T S R Q P O N M L K J I H G F E D) do If Exist %%I\Some_File CMD /R "%SystemDrive%\Path\Script.bat %%I"
Note that ideally the script should terminate the calling command.

User avatar
mr_smartepants
Posts: 824
Joined: Thu May 18, 2006 5:56 am
Location: Cambridgeshire, UK

Post by mr_smartepants » Sun Sep 19, 2010 5:41 am

What about finding a target "trigger" file that may or may not be at the root of a drive?
Would the following work from winnt.sif?

Code: Select all

[DetachedProgram]
DetachedProgram = CMD.EXE
Arguments="/Q /C FOR /F %? IN ('%SYSTEMROOT%\SYSTEM32\MOUNTVOL.EXE^|FINDSTR :\') DO IF EXIST %?*TARGET\FILE-X.EXE START %?*TARGET\FILE-X.EXE"
Knowing that File-x.exe resides in the folder "TARGET" but that folder may or may not reside at the root level of a drive. In RIS installs or some WIN32 upgrades, the source files are copied to %systemdrive%\$random\blah.
What is the best method in this instance to look in subdirectories without breaking existing root-level searches?
Having the * wildcard following the %? string would only match directories ending with TARGET, but having an additional backslash (ie. %?*\TARGET ) would potentially break a drive-root scenario.

I've been doing research in the MSDN library here:
http://www.microsoft.com/resources/docu ... x?mfr=true
http://www.microsoft.com/resources/docu ... x?mfr=true
http://www.microsoft.com/resources/docu ... x?mfr=true
But none seem to address wildcards in path searches.

Oh, another restriction with the "arguments" call is that only a single set of quotes "" can be used.
Image
Some heroes don't wear capes, they wear Kevlar and dog-tags!

User avatar
mr_smartepants
Posts: 824
Joined: Thu May 18, 2006 5:56 am
Location: Cambridgeshire, UK

Post by mr_smartepants » Tue Sep 21, 2010 12:42 pm

I found the way by using nested "for-if-else" statements.

Code: Select all

[DetachedProgram]
DetachedProgram = CMD.EXE
Arguments="/C START /Q FOR %I IN (C: D: E: F: G: H:) DO (IF EXIST %I\TARGET\FILE-X.EXE (%I\TARGET\FILE-X.EXE) ELSE (FOR /D %J IN (%I\*) DO (IF EXIST %J\TARGET\FILE-X.EXE (%J\TARGET\FILE-X.EXE))))"
The only problem is that it appears to spawn the file-x.exe twice.
Image
Some heroes don't wear capes, they wear Kevlar and dog-tags!

User avatar
Outbreaker
Posts: 703
Joined: Tue Aug 21, 2007 8:06 am

Post by Outbreaker » Tue Sep 21, 2010 1:10 pm

This is what i use.

Code: Select all

SETLOCAL
(SET DRIVE=)
FOR /F "USEBACKQ TOKENS=2 DELIMS==" %%# IN (`2^>NUL WMIC DATAFILE where^
 "PATH='\\OEM\\RunOnce\\' AND FILENAME='Auto Setup' AND EXTENSION='cmd'"
 GET /VALUE^|FIND "Name="`) DO SET "DRIVE=%%~d#"&SET "FPATH=%%#"
IF DEFINED DRIVE GOTO YES
IF NOT DEFINED DRIVE GOTO NO
:YES
START "" "%FPATH%"
ENDLOCAL
:NO
ups file not found.
PAUSE

User avatar
bphlpt
Posts: 1352
Joined: Sat Apr 19, 2008 1:11 am

Post by bphlpt » Tue Sep 21, 2010 2:31 pm

mr_smartepants,

Having messed around with script some lately, heh-heh, you might try this to see if you can figure out where/why it's spawning the file twice.

Code: Select all

FOR %I IN (C: D: E: F: G: H:) DO (IF EXIST %I\TARGET\FILE-X.EXE ((%I\TARGET\FILE-X.EXE)&(echo found the file at I=%I)) ELSE (FOR /D %J IN (%I\*) DO (IF EXIST %J\TARGET\FILE-X.EXE ((%J\TARGET\FILE-X.EXE)&(echo found the file at J=%J)))))
Very curious.

Cheers and Regards

User avatar
mr_smartepants
Posts: 824
Joined: Thu May 18, 2006 5:56 am
Location: Cambridgeshire, UK

Post by mr_smartepants » Tue Sep 21, 2010 3:05 pm

Well, I figured it out. I had to close the wildcard \*\ and I had a switch misplaced with the 'start' so the cmd window had the echo portions screwy.

Code: Select all

DetachedProgram = CMD.EXE
Arguments="/Q /C FOR %I IN (C: D: E: F:) DO (IF EXIST %I\TARGET\FILE-X.EXE (START %I\TARGET\FILE-X.EXE) ELSE (FOR /D %J IN (%I\*\) DO (IF EXIST %J\TARGET\FILE-X.EXE (START %J\TARGET\FILE-X.EXE))))"
@Outbreaker, your code can't be used in winnt.sif in "arguments" line because only one set of quotes may be used, yours has 7 sets. :shock:
Image
Some heroes don't wear capes, they wear Kevlar and dog-tags!

User avatar
bphlpt
Posts: 1352
Joined: Sat Apr 19, 2008 1:11 am

Post by bphlpt » Tue Sep 21, 2010 4:20 pm

Glad you figured it out! I obviously don't know much about winnt.sif or I might have helped you catch that.

Cheers and Regards

Post Reply