?
Solved

Batch File for Win7 PE

Posted on 2012-08-17
7
Medium Priority
?
996 Views
Last Modified: 2012-08-19
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.

  
@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
  )
)

Open in new window

0
Comment
Question by:Pat Clancy
  • 3
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Arman Khodabande
ID: 38306786
This code finds the first removable usb disk without that much effort:

@ 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
)
)
pause
0
 

Author Comment

by:Pat Clancy
ID: 38306809
Thank you

This code does basically the same thing. But thank you.
0
 
LVL 10

Expert Comment

by:Arman Khodabande
ID: 38307396
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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Pat Clancy
ID: 38307894
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.
0
 
LVL 10

Accepted Solution

by:
Arman Khodabande earned 1500 total points
ID: 38308128
As you said : "a variable would be set up"
If you mean to set a variable to contain drive letter (e.g. M), you already have the variable
%%I
We can change the code to this:
@ echo off
For /F "tokens=1" %%I In ('wmic logicaldisk get DeviceID^,DriveType^|Findstr "2"') Do (
If exist "%%I\" (
echo Disk found at %%I
Set Driveletter=%%I
)
)
pause

Open in new window


As you see I assigned a new variable which contains the usb drive address. Then you can use this variable to do anything you want. For example you can add:

 cd /d %Driveletter%

Open in new window


To the end of the script to change the current directory to the USB drive.
I hope I explained the right thing :D
0
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 38308486
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
)
)

Open in new window

this works just fine.
0
 

Author Comment

by:Pat Clancy
ID: 38309274
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

830 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