|
-
July 20th, 2002, 01:49 AM
#1
Choice
@echo off
@CHOICE /C EMZN /N /T:N,10 Cd-Rom drive D:, E:, M:, Z: or None?
IF ERRORLEVEL 1 SET DRIVE=drive D:
IF ERRORLEVEL 2 SET DRIVE=drive E:
IF ERRORLEVEL 3 SET DRIVE=drive M:
IF ERRORLEVEL 4 SET DRIVE=drive Z:
IF ERRORLEVEL 5 SET DRIVE=None
ECHO Your Cd-Rom drive is %DRIVE%
After the last line, i wanna execute a file called autorun.exe from the cd-rom drive. Wat line should I enter?
Thanks!
EveryONe I daTe alw@ys turns out to be sUCh a cyborg.
-
July 20th, 2002, 02:30 PM
#2
I would think:
%drive%\autorun
------------------
My
Two Cents
Dennis
Visit Politalk
-
July 20th, 2002, 07:33 PM
#3
Try it something like this:
Code:
@echo off
choice/c:demzn/t:n,10/n"Your CD-ROM drive is D:, E:, M:, Z: or None? "
if errorlevel 1 set CD-ROM=D:
if errorlevel 2 set CD-ROM=E:
if errorlevel 3 set CD-ROM=M:
if errorlevel 4 set CD-ROM=Z:
if errorlevel 5 set CD-ROM=
if (%CD-ROM%)==() goto Abort
echo Your CD-ROM drive is drive %CD-ROM%
echo.
if not exist %CD-ROM%\autorun.exe goto NotFound
%CD-ROM%\autorun.exe
goto Done
:Abort
echo Operation aborted. No Cd-ROM drive.
:NotFound
echo Error: AUTORUN.EXE was not found in the root directory of %CD-ROM%
:Done
for %%x in (CD-ROM CMDLINE) do set %%x=
:End
Note: This will only work if 1) CHOICE.COM is available in the user's PATH and 2) AUTORUN.EXE is in the root directory of the user's CD.
-
July 20th, 2002, 10:08 PM
#4
Eeyore, i did try your method. it gave me 'bad command or file name' error.
Vernon Frazee, i have yet to try yr method. After trying, will get back to post outcome.
Thanks alot Guys!
EveryONe I daTe alw@ys turns out to be sUCh a cyborg.
-
July 21st, 2002, 02:03 AM
#5
Vernon's
%CD-ROM%\autorun.exe
is virtually the same as my
%drive%\autorun.exe
His has more screen display which may indicate why it failed. But If his works in the same conditions, I will be scratching my head.
------------------
My
Two Cents
Dennis
Visit Politalk
-
July 21st, 2002, 05:02 AM
#6
The name of the environment variable doesn't really matter, ("drive" or "cd-rom"). What does matter is the string being assigned to it. In the original BATch file, "drive" is being set to one of the following entire strings:When you subsequently try to use the command:DOS is going to substitute the string, let's say "drive D:", in place of the "%drive%" portion of that command. This means that the command DOS is going to try and execute will be exactly:If you don't have a program or BATch file named "drive" in your current directory or in your PATH, this command will generate a "Bad command or file name" error.
All you need to do to keep this from happening is to remove the "drive " portion, (the word "drive" and the space), from each of the first four environment variables.
Also, if you have "drive" set to string "None" and you then use:DOS is going to issue this exact command:If your current location (drive:\path) doesn't contain a subdirectory named NONE with an AUTORUN.EXE in it, yep, yet another "Bad command or file name" error.
Another potential problem is, what if the user specifies the wrong drive letter and there is no AUTORUN.EXE in the root directory of that specified drive? "Bad command or file name".
And finally, what if the user hasn't inserted the CD? Yep, you guessed it, yet another "Bad command or file name" error.
-
July 21st, 2002, 12:53 PM
#7
I noticed an error in topdome's batch file.
DOS reads the IF ERRORLEVEL as such:
IF ERRORLEVEL >= <NUMBER> THEN DO <COMMAND>
This means that the highest value shares precedence with all other values up to that value.
So, list your errorlevel values backwards. In this case from 5 to 1, otherwise the IF ERRORLEVEL will always default to ERRORLEVEL 1 even though the actual value could be from 2 to 5.
ERRORLEVEL 0 is the default when no other conditions have been met, and doesn't have to be listed. This gives all the other errorlevel values a chance to divert the program appropriately before defaulting to the next listed command.
-
July 21st, 2002, 01:05 PM
#8
"I see" said the blind man. Thanks Vernon for clearing that up for me. I guess I need to copy and paste these, then test drive them, so I will find what I missed.
oldhermit, I missed that one too. Time for some remedial training.
------------------
My
Two Cents
Dennis
Visit Politalk
-
July 22nd, 2002, 04:17 AM
#9
Eeyore> "I see" said the blind man.
... as he picked up his hammer and saw. 
You're welcome.
oldhermit, you are correct if the BATch file was jumping to different lables for each errorlevel. But, all we're doing here is setting an environment variable.
For example, let's say the user pressed "E", the second choice. The first errorlevel test would be true so DOS would issue the command "set drive=drive d:". The next errorlevel test would also be true so DOS would issue the command "set drive=drive e:" (which would simply overwrite what was already in environment variable "drive"). All subsequent errorlevel tests will fail which means that "drive=drive e:" will still be in the environment.
Here, try the following little example. It'll show you exactly what I mean. If you were to run it and press say "5", the displayed errorlevel will start with "1", increment by "1" up to "5", and then stay there:
Code:
@echo off
set errorlevel=
choice/c:123456789/n"Press a number between 1 and 9: "
if errorlevel 1 set errorlevel=1
echo errorlevel=%errorlevel%
if errorlevel 2 set errorlevel=2
echo errorlevel=%errorlevel%
if errorlevel 3 set errorlevel=3
echo errorlevel=%errorlevel%
if errorlevel 4 set errorlevel=4
echo errorlevel=%errorlevel%
if errorlevel 5 set errorlevel=5
echo errorlevel=%errorlevel%
if errorlevel 6 set errorlevel=6
echo errorlevel=%errorlevel%
if errorlevel 7 set errorlevel=7
echo errorlevel=%errorlevel%
if errorlevel 8 set errorlevel=8
echo errorlevel=%errorlevel%
if errorlevel 9 set errorlevel=9
echo errorlevel=%errorlevel%
Make sense?
-
July 22nd, 2002, 10:41 AM
#10
Thanks Vernon for your detailed explanation. It worked !!!
The rest of you, thank you for sharing your knowledge as well. I didn't know that you can do so many things with CHOICE.
I would also like to know about 2 more things:
1) Let's say in a cd-rom, i create a batch file
@echo off
xcopy \Project\*.* c:\Project /y
will the above work, considering the fact that Project is a folder in the cd-rom and that play.exe exists in the folder. And also, will this work in all PCs, considering the fact that the cd-rom drive letter may be different in diff PCs.
Need to know about this before I burn the rom.
2) I want to rename a file on a local PC. Let's say :
ren c:\windows\hosts.old hosts
I have created this as a batch file and it resides in a shared folder in the server. If users execute this file from the server, will it have any affect on their client PC or will the command run on the server itself? If it runs on the server, how do I change it to run on the client PCs?
Thanks!
Thanks!
Last edited by topdome; July 22nd, 2002 at 10:36 PM.
EveryONe I daTe alw@ys turns out to be sUCh a cyborg.
-
July 22nd, 2002, 12:04 PM
#11
Thanks to the Maestro...
-
July 24th, 2002, 06:24 AM
#12
@echo off
xcopy \Project\*.* c:\Project /y
This will work if the user is on the same drive as the source files. The source portion of your command, "\Project\*.*", tells XCOPY to copy all files, (*.*), from a directory named "Project" that is located off the root directory , (the leading "\"), of the current drive, ("current drive" because no other drive was specified).
One potential problem I see is the use of the /y parameter. Personally, I'd be hesitant to overwrite any files in someone else's "C:\Projects" directory.
Another problem I foresee is the lack of the "/i" parameter. If the destination directory "C:\Projects" does not exist, XCOPY is going to pause with a:- Does Project specify a file name
or directory name on the target
(F = file, D = directory)? message.
ren c:\windows\hosts.old hosts
REName will attempt to do exactly as instructed ... rename a file in the "c:\windows" directory, on the user's current machine, that is now named "hosts.old" with a new name of "hosts". (If the user was on the server, it would look on drive C: on the server. If the user was on a client, it would look on drive C: on the client).
My first question is, what do you want to happen if a "hosts" file already exists in the "C:\Windows" directory? The REName command is going to fail with a:- Duplicate file name or file in use
error if it does.
-
July 24th, 2002, 08:26 AM
#13
Hi Vernon!
Thanks for your detailed exp abt the xcopy command with the /i parameter. I included it. It automatically created a specified directory.
I create the project files at home and thus burn it in a cd and then copy it back into my company's server. So, by default, I want to overwrite the files. That's why I wanted the /y parameter.
As for the hosts file, by default, the network login script will rename all existing hosts file in all PCs to hosts.old
I have decided to change to command to the following:
if exist c:\windows\hosts.old ren c:\windows\hosts.old hosts
any comments??
thanks!
EveryONe I daTe alw@ys turns out to be sUCh a cyborg.
-
July 25th, 2002, 05:08 AM
#14
If both files, "HOSTS" and "HOSTS.OLD", already exist in C:\Windows, the command:- if exist c:\windows\hosts.old ren c:\windows\hosts.old hosts
will generate the error:- Duplicate file name or file in use
To avoid this, I'd use:- if exist c:\windows\hosts.old if not exist
c:\windows\hosts ren c:\windows\hosts.old hosts (Unwrap that line).
-
July 25th, 2002, 09:10 AM
#15
thanks Vernon!
I didn't think of that!
EveryONe I daTe alw@ys turns out to be sUCh a cyborg.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|