Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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
Echo. Windows 7 64 Bit Ent Basic Desktops
Echo A. 790 Windows 7 - Basic
Echo I. Exit

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)

goto start

REM DISKPART /s %SecondPath%BatchFiles\Make-Partition.txt

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

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

Copy %SecondPath%Unattended\unattend.XML o:\Windows\System32\sysprep\unattend.XML /y

xcopy %SecondPath%Drivers\790\*.* o:\Windows\INF\790\ /E /Q /Y

MD o:\Windows\Setup\Scripts\
Copy %SecondPath%BatchFiles\SetupComplete.cmd o:\Windows\Setup\Scripts\ /y

Goto Done

share|improve this question
Welcome to Super User! Please take care to format your posts correctly. Insert code, select it and press Ctrl-K to indent it so it is shown as code. For the future, check our formatting help. – slhck Jun 18 '12 at 17:36
up vote 0 down vote accepted

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%.

share|improve this answer
What did end up working was to use: – LunchBox Jun 19 '12 at 19:11
What did work was to end up using the first variable that I set. The first variable is called %MainPath% and was recommended by a co-worker to pass that variable to the second batch file but sue a different name for the vairable to prevent confusion. Well, that did not work but what did work was to se: %MainPatch%\Images*.wim etc. I will test as you suggestion though for my own knowledge. Thanks – LunchBox Jun 19 '12 at 19:16

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

share|improve this answer
Never heard of that command but it should pretty good. I will test with it - thanks – LunchBox Jun 19 '12 at 19:19

You should check "\sources\boot.wim" file, open this file, and then check these "\tools\imagex.exe and bcdboot.exe" files have correct directory in boot.wim.

share|improve this answer
yes everything is in the correct directory and if I run all manually it works. Is the batch file that does not. Harry Johnson's response actually helped solve my issue – LunchBox Jun 19 '12 at 19:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.