WinPE, Startnet.CMD and passing variables to second batch file not working

Posted on

QUESTION :

I don’t know scripting or PowerShell (yes I need to learn something). I’m not an expert batch file maker either.

I have a WinPE flash drive which I used to deploy OS images. I have the WIM, drivers and anything needed else outside the WinPE environment to ensure that
Updates, changes are easier for me to make.

I use the “STARTNET.CMD” batch file which is part of the WinPE.

The reason to go through the letter drives is that the WinPE always gets the X letter drive assigned. The flash drive itself can receive a random letter which always changes.

My deployment menu is located on the flash drive it self and not inside the WinPE. This is so that if I need to make a change I don’t have to re-do the WinPE.

I am able to locate the “menu.bat” batch file and launch it.
I use a variable to capture the letter drive.
I call the second batch file named “menu.bat” and pass the variable to it.

When the second batch file loads, I believe that I am calling the variable correctly. If I break out of the batch file I can echo the variable and see the expected reply.
The issue is that I can’t use the variable to work with anything on the second batch file.
In my test, I can get this to work over and over.
When it runs from the real USB flash drive it does not work.
I removed comments from the second batch file to make it smaller.

My issue is that files below all get a message stating that the system cannot find the path specified.

Diskpart
Imagex.exe
bcdboot.exe

Why can’t I get the varible to properly function when I try to using example “ImageX.exe”?

Contents of the Startnet.cmd

@echo off
for %%p in (a b 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 %%p:Tools set w=%%p
Set execpatch=%w%Tools
call %w%:Menu.bat Tools

Contents of the Menu.BAT

@echo off
set SecondPath=%1
cls
:Start
cls
Echo.
Echo.==============================================================
Echo. Windows 7 64 Bit Ent Basic Desktops
Echo.==============================================================
Echo.
Echo A. 790 Windows 7 - Basic
Echo.
Echo.
Echo I. Exit
Echo.
Echo.

set /p choice=Choose your option = 

if not '%choice%'=='' set choice=%choice:~0,1%

if '%choice%'=='a' goto 790_Windows_7_Basic

echo "%choice%" is not a valid (answer/command)
echo.

goto start
:790_Windows_7_Basic

REM DISKPART /s %SecondPath%BatchFilesMake-Partition.txt

%SecondPath%imagex.exe /apply %SecondPath%ImagesWin7-64b-Ent-Basic-SysPreped.wim 1 o: /verify

%SecondPath%bcdboot.exe o:Windows /s S:

Copy %SecondPath%Unattendedunattend.XML o:WindowsSystem32sysprepunattend.XML /y

xcopy %SecondPath%Drivers790*.* o:WindowsINF790 /E /Q /Y

MD o:WindowsSetupScripts
Copy %SecondPath%BatchFilesSetupComplete.cmd o:WindowsSetupScripts /y

Goto Done

:Done
Exit

ANSWER :

From the looks of it, the last line in your startnet.cmd file should be

call %w%:Menu.bat %w%:Tools

since menu.bat is apparently expecting the first argument to be the complete path to the Tools directory, including the drive letter.

Note that startnet.cmd sets an environment variable named w which menu.bat could use (but currently doesn’t!) so another solution would be to replace all the instances of %SecondPath% with %w%:%SecondPath%.

Does using Setx help? It modifies the user or system environment environment. Look at Setx /? for more

You should check “sourcesboot.wim” file, open this file, and then check these “toolsimagex.exe and bcdboot.exe” files have correct directory in boot.wim.

Leave a Reply

Your email address will not be published.