在 Windows 安装期间从 autounattend.xml 运行批处理文件

在 Windows 安装期间从 autounattend.xml 运行批处理文件

我想在windowsPE无人值守的 Windows 安装阶段运行一个批处理文件,autounattend.xml只要我从它的路径启动该批处理文件,它就可以正常工作,如下所示:

<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

驱动器号可能不同,如果找不到,则安装程序会失败D:\startup.bat

  • 为了搜索该文件,我发现了这个脚本,当我从终端运行它时它工作正常,但从应答文件运行时失败:
      <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>
    

我尝试过几十种变化:
使用引号、带/不带括号、echo代替startcmd不带.exe/c/k、使用&&以及创建变量并SET通过调用它%var%

  • 由于windowsPE应答文件第 1 阶段的错误,安装总是失败,我不知道原因:
    2023-11-21 11:25:21,  Info  IBS Command 5: 0x00000000
    
    2023-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.]
    

答案1

我最终通过将批处理文件放入启动 Windows 安装程序 (boot.wim) 的 WindowsPE 映像中解决了这个问题。这样,该文件始终位于 X:\ 驱动器中,我只需使用以下命令从应答文件启动它即可"cmd.exe /k X:\Windows\Setup\startup.bat"

相关内容