Search code examples
windowsbatch-filedism

How can i know total number of index available in a Windows index.wim file using DISM on the command line


I want to know the total number of index available in a install.wim file located in windows source using dism and store that number in a numeric variable in same dos batch script. So far I have tried below commands in a batch.

 for /L %%A IN (1, 1, 20) Do (
 PAUSE
 dism /Get-WimInfo /WimFile:h:\research\Win7x64\InstallWin7_aio\sources\install.wim /index:%%A | Find "ProductType : WinNT" > H:\SCM\VERCHK.TXT 

 FINDSTR "ProductType : WinNT" "H:\SCM\VERCHK.TXT" > NUL
 IF %ERRORLEVEL% == 0 set /A INTINDEX+=1
 START H:\SCM\VERCHK.TXT
 )
 cls
 ECHO %INTINDEX%
 pause

I will like to mention that I am trying to complete the above process in my Windows 10 Pro x64.


Solution

  • Ok. I got my answer and this is what i will do to get my desired result.

     @echo off
    
     if exist %TEMP%\scm (RD %TEMP%\scm /S /Q)
     md %TEMP%\scm
    
     for /L %%A IN (1, 1, 25) Do (
    
     dism /Get-WimInfo /WimFile:h:\research\Win7\InstallWin7_aio\sources\install.wim /index:%%A > %TEMP%\scm\%%A.txt
     timeout 0 >nul
     Find /i "Error:" "%Temp%\scm\%%A.TXT" > nul && (
          set "Index=%%A"
            goto:next
     ) 
     )
    
     exit/b
    
     :next
     set /A Ti = %Index% - 1
     ECHO There are %Ti% number of indexes in the image.
    
     pause