I want to run a batch file during the windowsPE phase of an unattended Windows setup, and the autounattend.xml works fine as long as I launch the batch file from its path like this:
<RunSynchronousCommand wcm:action="add">
<Description>StartUp script</Description>
<Path>cmd.exe /k D:\startup.bat<Path>
<Order>6</Order>
</RunSynchronousCommand>
2023-11-21 11:41:53, Info IBS Command 5: 0x00000000
2023-11-21 11:41:56, Info IBS Successfully executed command 'cmd.exe /k "D:\startup.bat"' (exit code 0x00000000)
2023-11-21 11:41:56, Info IBS STATUS: SUCCESS (0x00000000)
2023-11-21 11:41:56, Info IBS ==== executing user-specified asynchronous commands ====
2023-11-21 11:41:56, Info IBS STATUS: SUCCESS (0x00000001)
2023-11-21 11:41:56, Info IBS ==== Applying shutdown settings ====
2023-11-21 11:41:56, Info IBS No shutdown setting was specified
2023-11-21 11:41:56, Info IBS STATUS: SUCCESS (0x00000001)
2023-11-21 11:41:56, Info IBS Successfully applied WinPE bootstrap unattend settings
The drive letter can be different, and setup fails when it doesn't find D:\startup.bat
- To search for the file, I found this script, and it works fine when I run it from a terminal, but fails when it's run from the answer file:
<RunSynchronousCommand wcm:action="add"> <Description>StartUp script</Description> <Path>cmd.exe /k "(FOR %i IN (C D E F G H I J K L N M) DO IF EXIST %i:\startup.bat start %i:\startup.bat)"</Path> <Order>6</Order> </RunSynchronousCommand> </RunSynchronous>
I have tried dozens of variations:
using quotes, with/out parenthesis, echo instead of start, cmd without .exe, /c or /k, using &&, and creating a variable with SET and calling it via %var%
- Setup always fails due to an error within the
windowsPEPass 1 of the answer file, and I can't figure out why:2023-11-21 11:25:21, Info IBS Command 5: 0x000000002023-11-21 11:27:22, Info IBS Successfully executed command 'cmd.exe /k "FOR %i IN (C D E F G H I J K L N M) DO IF EXIST %i:\startup.bat start %i:\startup.bat"' (exit code 0xc000013a) 2023-11-21 11:27:22, Info IBS STATUS: FAILURE (0xc000013a)
2023-11-21 11:27:22, Info IBS ==== executing user-specified asynchronous commands ==== 2023-11-21 11:27:22, Info IBS STATUS: SUCCESS (0x00000001)
2023-11-21 11:27:22, Info IBS ==== Applying shutdown settings ==== 2023-11-21 11:27:22, Info IBS No shutdown setting was specified 2023-11-21 11:27:22, Info IBS STATUS: SUCCESS (0x00000001)
2023-11-21 11:27:22, Error [0x0604a8] IBS Failed applying WinPE bootstrap unattend settings with status 0xc000013a
2023-11-21 11:27:22, Info [0x0640ae] IBSLIB PublishMessage: Publishing message [The Windows PE bootstrap setting specified in the automatic response file could not be applied.]