Pat Clancy
asked on
Batch File for Win7 PE
I have the following code in a batch file to help me find a USB drive. This batch file looks for a directory that I placed a folder on the USB drive to help with the search. Generally the USB letter is unknown so rather than just fumbling around and entering letters until I stumble upon the right one I have found this bit of code to put in the batch.
I am wondering if there is a way to use the result "%%d" in a variable to finish off the batch by going to the found drive. I tried just using %%d: to try and change to the Found Drive but that doesn't work.
Note that this works really well in the PE but throws a fit in Windows 7. ( you get about 4 "No Disk" Errors which is not really a problem because I know it works in the PE environment)
Thank you for any advice and help you can send my way.
I am wondering if there is a way to use the result "%%d" in a variable to finish off the batch by going to the found drive. I tried just using %%d: to try and change to the Found Drive but that doesn't work.
Note that this works really well in the PE but throws a fit in Windows 7. ( you get about 4 "No Disk" Errors which is not really a problem because I know it works in the PE environment)
Thank you for any advice and help you can send my way.
@echo off
setLocal Enabledelayedexpansion
for %%d in (c 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 %%d:\B75_hp\ (
ECHO USB Drive Has Been Found at : %%d
)
)
ASKER
Thank you
This code does basically the same thing. But thank you.
This code does basically the same thing. But thank you.
What do you mean by saying "Finish off" ?
Do you want the batch to open the drive in explorer or change the command prompt working directory to that drive?
Do you want the batch to open the drive in explorer or change the command prompt working directory to that drive?
ASKER
By finishing off I mean I would like the that filed automatically go to the drive. For example if the directory is located on the USB drive and has been found at "M" then a variable would be set up so that the last command in the batch file would read M:
Keep in mind are working in a preinstall environment not Windows so all we are dealing with is a DOS prompt.
Thanks For your Help.
Keep in mind are working in a preinstall environment not Windows so all we are dealing with is a DOS prompt.
Thanks For your Help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no points please
@ echo off
For /F "tokens=1" %%I In ('wmic logicaldisk get DeviceID^,DriveType^|Findstr "2"') Do (
If Exist "%%I\B75_hp\" (
echo Disk found at %%I
setx usbdrive %%I
cd /D %usbDrive%
b75_hp\foundme.cmd
)
)
this works just fine.
ASKER
Thank you all for your help. Both of the variations work just fine. I dropped them into the CD and booted into the PE and shazam no more fumbling around looking for the USB Drive.
Thank you
Thank you
@ echo off
For /F "tokens=1" %%I In ('wmic logicaldisk get DeviceID^,DriveType^|Finds
If Exist "%%I\B75_hp\" (
echo Disk found at %%I
)
)
pause