获取Windows映像中某个体系结构的索引号

时间:2016-09-25 14:20:30

标签: windows batch-file cmd dism

我有一个包含多种体系结构的Windows 7映像(WIM)。我想知道图像中特定架构的索引号。

例如,图像包含(无特定顺序):

  • Windows 7 Ultimate x64
  • Windows 7 Ultimate x86
  • Windows 7 Professional x64
  • Windows 7 Professional x86
  • Windows 7家庭高级版x64
  • Windows 7 Home Premium x86

我没有以上版本的任何的索引号。

我想在Windows图像文件中检索Windows 7 Professional x64的索引号。我该怎么做呢:

到目前为止,我想出了:

if exist %TEMP%\scm (RD %TEMP%\scm /S /Q)
md %TEMP%\scm

for /L %%A IN (1, 1, 12) Do (

dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:%%A > %TEMP%\scm\%%A.txt
Findstr "Windows 7 Ultimate" %Temp%\scm\%%A.TXT && Findstr "x64" %Temp%\scm\%%A.TXT > nul
IF %ERRORLEVEL% == 0 (ECHO "It is Windows 7 Ultimate x64")

)

pause

我得到以下输出

H:\>for /L %A IN (1 1 12) Do (
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:%A  1>C:\Users\Tarak\AppData\Local\Temp\scm\%A.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\%A.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\%A.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:1  1>C:\Users\Tarak\AppData\Local\Temp\scm\1.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\1.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\1.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Name : Windows 7 Starter
Description : Windows 7 Starter
Size : 8,072,604,598 bytes
Version : 6.1.7601
ServicePack Build : 17514
Files : 46887
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:2  1>C:\Users\Tarak\AppData\Local\Temp\scm\2.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\2.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\2.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Name : Windows 7 Home Basic
Description : Windows 7 Home Basic
Size : 8,125,226,573 bytes
Version : 6.1.7601
ServicePack Build : 17514
Files : 47090
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:3  1>C:\Users\Tarak\AppData\Local\Temp\scm\3.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\3.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\3.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Name : Windows 7 Home Premium
Description : Windows 7 Home Premium
Version : 6.1.7601
ServicePack Build : 17514
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:4  1>C:\Users\Tarak\AppData\Local\Temp\scm\4.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\4.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\4.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Name : Windows 7 Professional
Description : Windows 7 Professional
Size : 8,447,825,392 bytes
Version : 6.1.7601
ServicePack Build : 17514
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:5  1>C:\Users\Tarak\AppData\Local\Temp\scm\5.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\5.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\5.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Name : Windows 7 Ultimate
Description : Windows 7 Ultimate
Size : 8,607,765,255 bytes
Version : 6.1.7601
ServicePack Build : 17514
Edition : Ultimate
Files : 48718
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo     /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:6 1>C:\Users\Tarak\AppData\Local\Temp\scm\6.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\6.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\6.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Name : Windows 7 Home Basic
Description : Windows 7 Home Basic
Size : 11,707,704,502 bytes
Version : 6.1.7601
ServicePack Build : 17514
Files : 64267
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:7  1>C:\Users\Tarak\AppData\Local\Temp\scm\7.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\7.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\7.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Index : 7
Name : Windows 7 Home Premium
Description : Windows 7 Home Premium
Version : 6.1.7601
ServicePack Build : 17514
Modified : 21-Apr-11 - 06:07:36
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:8  1>C:\Users\Tarak\AppData\Local\Temp\scm\8.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\8.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\8.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Name : Windows 7 Professional
Description : Windows 7 Professional
Version : 6.1.7601
ServicePack Build : 17514
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:9  1>C:\Users\Tarak\AppData\Local\Temp\scm\9.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\9.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\9.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Details for image : h:\research\Win7x64\InstallWin7_aio\sources\install.wim
Name : Windows 7 Ultimate
Description : Windows 7 Ultimate
Version : 6.1.7601
ServicePack Build : 17514
Edition : Ultimate
Directories : 13735
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo    /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:10  1>C:\Users\Tarak\AppData\Local\Temp\scm\10.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\10.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\10.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Error: 87
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:11  1>C:\Users\Tarak\AppData\Local\Temp\scm\11.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\11.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\11.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)  
Error: 87
"It is Windows 7 Ultimate x64"
0

H:\>(
dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:12  1>C:\Users\Tarak\AppData\Local\Temp\scm\12.txt
Findstr "Windows 7 Ultimate" C:\Users\Tarak\AppData\Local\Temp\scm\12.TXT   && Findstr "x64" C:\Users\Tarak\AppData\Local\Temp\scm\12.TXT  1>nul
IF 0 == 0 (ECHO "It is Windows 7 Ultimate x64" )
ECHO 0
)
Error: 87
"It is Windows 7 Ultimate x64"
0

1 个答案:

答案 0 :(得分:2)

如果您想直接测试delayed expansion,请启用!errorlevel!,并最好将/i开关与findstr一起使用:

或直接使用&&

@echo off

if exist %TEMP%\scm (RD %TEMP%\scm /S /Q)
md %TEMP%\scm

for /L %%A IN (1, 1, 12) Do (

dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:%%A > %TEMP%\scm\%%A.txt
Find /i "Windows 7 Ultimate" "%Temp%\scm\%%A.TXT" && Find /i "Architecture : x64" "%Temp%\scm\%%A.TXT" && (
      set "Index=%%A"
      goto:next
) 
)

exit/b

:next
ECHO "Windows 7 Ultimate x64" is in Index : %Index%