Jump to content











Photo
- - - - -

WinPE on USB running batch in root?

winpe usb flash batch

  • Please log in to reply
7 replies to this topic

#1 Flux

Flux

    Newbie

  • Members
  • 18 posts
  • Location:Edmonton, AB
  •  
    Canada

Posted 03 August 2016 - 11:10 PM

Hey guys, I'm a bit of a nub with WinPE. I have in the past created a bootable PE environment which booted over PXE, and had it launch a batch file which allowed you to run different tools from a network share.

 

What I want to do is boot a WinPE environment from a flash drive, which launches a batch file stored on the flash drive's root directory, so I can launch applications directly from the flash drive's subdirectories, rather than having to rely on a network share. This would be particularly useful in the field, where I don't have access to the network share.

 

I've been having trouble finding any insight on automatically detecting which drive is the flash drive and launching a script from it. I can only ever find stuff on launching applications which are baked into the WIM itself.

 

Any insight would be greatly appreciated! Thanks! :)



#2 spleenharvester

spleenharvester

    Member

  • Members
  • 92 posts
  •  
    United Kingdom

Posted 03 August 2016 - 11:15 PM

Hey guys, I'm a bit of a nub with WinPE. I have in the past created a bootable PE environment which booted over PXE, and had it launch a batch file which allowed you to run different tools from a network share.
 
What I want to do is boot a WinPE environment from a flash drive, which launches a batch file stored on the flash drive's root directory, so I can launch applications directly from the flash drive's subdirectories, rather than having to rely on a network share. This would be particularly useful in the field, where I don't have access to the network share.
 
I've been having trouble finding any insight on automatically detecting which drive is the flash drive and launching a script from it. I can only ever find stuff on launching applications which are baked into the WIM itself.
 
Any insight would be greatly appreciated! Thanks! :)

 
I do this with things like OpenOffice to keep the WIM size down - have a script autodetect the drive, then launch another script from that drive to start OpenOffice. This is how I do it, you could try something like this launched from startnet.cmd:

  • Just change the pathing variable to the path to the script on your drive.
@echo off
set found=0

:start
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W Y Z) do (
if exist %%a:\OpenOfficePortable\OpenOfficePortable.exe (
set found=1
set foundloc=%%a
))
if "%found%"=="1" (
goto skip
)
if "%found%"=="0" (
echo Msgbox "ERROR: Could not locate the stick containing \OpenOfficePortable\OpenOfficePortable.exe. Please plug it back in and then run this script again.", vbSystemModal + vbCritical, "OpenOffice Launcher" > %~dp0openoffice2.vbs
start %~dp0openoffice2.vbs
exit
)
exit

:skip
echo.
echo CreateObject("WScript.Shell").Popup "Launching OpenOffice from USB, please wait...", 7, "OpenOffice Launcher", 64 >%~dp0openoffice2.vbs
start %~dp0openoffice2.vbs
start %foundloc%:\OpenOfficePortable\OpenOfficePortable.exe
exit

Do note that there is probably a more efficient way of doing this code-wise, but this has always worked reliably for me.   :thumbsup:


Edited by spleenharvester, 03 August 2016 - 11:23 PM.


#3 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 August 2016 - 07:19 AM

Please do note how the above will throw an error if the computer has a media card reader (or other device that maps a drive letter even if media is not present).

Compare with:

http://www.msfn.org/...#comment-895361

 

:duff:

Wonko



#4 spleenharvester

spleenharvester

    Member

  • Members
  • 92 posts
  •  
    United Kingdom

Posted 04 August 2016 - 08:00 AM

Please do note how the above will throw an error if the computer has a media card reader (or other device that maps a drive letter even if media is not present).

Compare with:

http://www.msfn.org/...#comment-895361

 

:duff:

Wonko

 

I had this happen once and couldn't figure out what was causing it. Assumed the machine was weird. Cheers for pointing that one out.  :)


Edited by spleenharvester, 04 August 2016 - 08:00 AM.


#5 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 August 2016 - 10:35 AM

Yep, besides a number of desktops a few notebooks/netbooks have the SD card connected to an internal USB bus and behave the same, the issue is with the "IF EXIST", using mountvol (which may or may be not present in a PE) is optional, it is only used to "shorten" the loop.
 
Anyway, even if using the explicit letter list, it is a good idea to exit the loop as soon as first instance is found , like in the given example, in your case that would be:

@ECHO OFF
SET TAGFILE=\openofficeportable\openofficeportable.exe
FOR %%? 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 (
DIR "%%?:%TAGFILE%">nul 2>&1&&SET DRIVE=%%?:&&GOTO :found
)
ECHO Not found
GOTO :EOF
:found
ECHO %TAGFILE% found on Drive %Drive%
(you can omit a and b as those - unless explicitly mapped overriding automount - are assigned by windows to floppy disks)
 
 
:duff:
Wonko

#6 Flux

Flux

    Newbie

  • Members
  • 18 posts
  • Location:Edmonton, AB
  •  
    Canada

Posted 04 August 2016 - 06:26 PM

Thanks guys! very helpful! :)



#7 cdob

cdob

    Gold Member

  • Expert
  • 1344 posts

Posted 04 August 2016 - 07:06 PM

Which WinPE version do you use?

Do you launch this automatic at boot?
Do you launch this manually after boot?
There may be a timing issue.
Therefore WaitForRemovableStorage was included
https://technet.micr...y/dd744592.aspx
 
rem detect PE boot drive, Windows 7
rem https://technet.microsoft.com/library/dd744592.aspx
WPEutil.exe WaitForRemovableStorage
WPEutil.exe UpdateBootInfo
for /f "tokens=3" %%a  in ('reg.exe query  HKLM\SYSTEM\CurrentControlSet\Control /v PEBootRamdiskSourceDrive') do set PEDrive=%%a

echo PEDrive %PEDrive%

  • wimb likes this

#8 Flux

Flux

    Newbie

  • Members
  • 18 posts
  • Location:Edmonton, AB
  •  
    Canada

Posted 05 August 2016 - 04:19 PM

Thanks, I'll keep it in mind. So far the previous suggested method works great, although if I experience any situation where it doesn't detect, I'll switch methods to your suggestion. Great to know that's in there!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users