Error when trying to use command line options

cshirley101675

New Member
Messages
14
Reaction score
0
Hi folks, I am trying to create an automated solution to refresh my build images, but keep running into a problem with this error. I can verify that the install.wim file does exist prior to launching.

NTLite_Command_Error.jpg

if exist "D:\NTLite_Files\Win11_Pro_Image2\" rmdir "D:\NTLite_Files\Win11_Pro_Image2\" /s /q
xcopy "D:\NTLite_Files\Win11_Pro_Image1" "D:\NTLite_Files\Win11_Pro_Image2\" /s /e /h
xcopy "D:\NTLite_Files\$OEM$" "D:\NTLite_Files\Win11_Pro_Image2\sources\$OEM$\" /s /e /h

powershell -command "Start-Sleep -Seconds 20"

D:\NTLite\NTLite.exe /LoadImage:"D:\NTLite_Files\Win11_Pro_Image2\sources\install.wim" /ImageIndex:1 /LoadPreset:"Carlton_Win11" /CreateIso:"D:\NTLite_Files\Carlton_Win11.iso" /IsoLabel:"Carlton_Win11" /ExitAfter:1

if exist "D:\NTLite_Files\Win11_Pro_Image2\" rmdir "D:\NTLite_Files\Win11_Pro_Image2\" /s /q


I think it is failing on this command line:
D:\NTLite\NTLite.exe /LoadImage:"D:\NTLite_Files\Win11_Pro_Image2\sources\install.wim" /ImageIndex:1 /LoadPreset:"Carlton_Win11" /CreateIso:"D:\NTLite_Files\Carlton_Win11.iso" /IsoLabel:"Carlton_Win11" /ExitAfter:1

Any idea why?

Note: I am running this via a Jenkins script (locally on my desktop in interactive mode). NTLite does launch, but I always get this error.

Thanks in advance.
 
This is a classic batch scripting gotcha! The reason NTLite is complaining that it can't find the file is because your script is deleting the folder while NTLite is trying to open it.

By default, when a Windows batch script launches a GUI application (like NTLite.exe), it does not wait for the application to close. It launches the program and immediately moves on to the next line.

In your script, as soon as NTLite starts booting up, your script immediately triggers the final rmdir command, destroying the Win11_Pro_Image2 folder before NTLite actually has a chance to load the install.wim file.

To fix this, you need to use the start /wait command. This forces the batch script to pause execution until NTLite completely finishes its task and closes.

Here is your corrected script, along with a few other minor stability improvements:

Code:
@Echo off

:: 1. Clean up old working directory if it exists
if exist "D:\NTLite_Files\Win11_Pro_Image2\" rmdir "D:\NTLite_Files\Win11_Pro_Image2\" /s /q

:: 2. Copy base image and OEM files
:: Added /i (assumes destination is a directory) and /y (suppresses overwrite prompts) for bulletproof automation.
xcopy "D:\NTLite_Files\Win11_Pro_Image1" "D:\NTLite_Files\Win11_Pro_Image2\" /s /e /h /i /y
xcopy "D:\NTLite_Files\$OEM$" "D:\NTLite_Files\Win11_Pro_Image2\sources\$OEM$\" /s /e /h /i /y

:: (Note: The 20-second PowerShell sleep was removed. 'xcopy' is a synchronous command;
:: the script will not naturally proceed until the file copy is 100% complete anyway.)

:: 3. Run NTLite and WAIT for it to finish
start /wait "" "D:\NTLite\NTLite.exe" /LoadImage:"D:\NTLite_Files\Win11_Pro_Image2\sources\install.wim" /ImageIndex:1 /LoadPreset:"Carlton_Win11" /CreateIso:"D:\NTLite_Files\Carlton_Win11.iso" /IsoLabel:"Carlton_Win11" /ExitAfter:1

:: 4. Clean up after NTLite exits
if exist "D:\NTLite_Files\Win11_Pro_Image2\" rmdir "D:\NTLite_Files\Win11_Pro_Image2\" /s /q
 
Back
Top