我用一个答案文件运行 sysprep,它在专门的配置阶段运行批处理脚本,批处理脚本获取硬盘索引并在硬盘上运行 diskpart,但它不起作用
所有文件位于 c:emp
c: emp\unattend.xml
c: emp estdisk.bat
c:emp.txt
c:emp.txt
使用无人值守应答文件的 sysprep 如下所示:
sysprep /generalize /oobe /reboot unattend:c: emp\unattend.xml
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="specialize">
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RunAsynchronous>
<RunAsynchronousCommand wcm:action="add">
<Order>1</Order>
<Path>cmd /c C:\Temp\testdisk.bat</Path>
<Description>test</Description>
</RunAsynchronousCommand>
</RunAsynchronous>
</component>
</settings>
<cpi:offlineImage cpi:source="wim:e:/installwin10pro.wim#Windows 10 Pro" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>
testdisk.bat 如下所示:
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
md c:\temp\testdir1
set "params=%*"
cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/c cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )
Set "Index="
For /F "Tokens=2 Delims==" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe
DiskDrive Where "Model Like 'ST%%' And Size > 300000000000" Get Index
/Value 2^>NUL') Do For %%H In (%%G) Do Set "Index=%%H"
If Not Defined Index GoTo :EOF
Echo Your Disk Index is %Index%
md c:\temp\testdir2
echo select disk %index% > 1.txt
type 2.txt >> 1.txt
diskpart /s c:\temp\1.txt
Pause
c: emp .txt 为空,用于保存硬盘的索引,c: emp .txt 如下所示:
clean
convert gpt
create partition primary size = 1000
format quick fs=ntfs
assign
create partition primary size = 1000
format quick fs=ntfs
assign
最后进入操作系统时,我检查了,批处理脚本创建了 testdir1 和 testdir2,2.txt 的内容附加到 1.txt 的末尾,如下所示:
select disk 1
clean
convert gpt
create partition primary size = 1000
format quick fs=ntfs
assign
create partition primary size = 1000
format quick fs=ntfs
assign
但是diskpart好像没有运行,
我尝试在安装后运行 diskpart /s 1.txt,它运行良好,但为什么它在无人值守安装过程中不起作用?
谁能指出问题出在哪里