murphy78 DiskPart and Apply Image Script

Discussion in 'Scripting' started by murphy78, Apr 2, 2014.

  1. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    For the $OEM$ folder copy, it's much more complicated to automate than to simply copy.
    For the scripted version, this is what I have in the diskpart-apply-image script:
    Code:
    :OEMFOLDERCOPY
    REM Use a set var="" else the IF NOT EXIST statement will crash the script
    
    SET OEMFOLDER=""
    FOR %%i IN (Z Y X W V U T S R Q P O N M L K J I H G F E D C B A) DO (IF EXIST %%i:\Sources\$OEM$\ SET OEMFOLDER=%%i:\Sources\$OEM$&GOTO :OEMPROCEED)
    
    IF EXIST Z:\Windows\syswow64 (
    FOR %%i IN (Z Y X W V U T S R Q P O N M L K J I H G F E D C B A) DO (IF EXIST %%i:\x64\Sources\$OEM$\ SET OEMFOLDER=%%i:\x64\Sources\$OEM$&GOTO :OEMPROCEED)
    ) ELSE (
    FOR %%i IN (Z Y X W V U T S R Q P O N M L K J I H G F E D C B A) DO (IF EXIST %%i:\x86\Sources\$OEM$\ SET OEMFOLDER=%%i:\x86\Sources\$OEM$&GOTO :OEMPROCEED)
    )
    IF NOT EXIST %OEMFOLDER% GOTO :MULTIBOOTOPTION
    
    :OEMPROCEED
    IF !FASTSETUP! EQU 1 GOTO:AFTEROEMCHOICE
    ECHO ===============================================================================
    ECHO.                  $OEM$ Folder was detected in your system
    ECHO -------------------------------------------------------------------------------
    ECHO Copy the files from %OEMFOLDER%?
    ECHO -------------------------------------------------------------------------------
    %CHOICEEXE% /c yn /n /m "Copy the $OEM$ folder contents to the current Windows Partition? (Y/N): "
    IF !ERRORLEVEL! NEQ 1 GOTO :MULTIBOOTOPTION
    
    :AFTEROEMCHOICE
    echo.
    Echo Copying contents of %OEMFOLDER% to system partition
    if exist %OEMFOLDER%\$$\ (xcopy %OEMFOLDER%\$$\* Z:\Windows\ /cherkyi)
    if exist %OEMFOLDER%\$1\ (xcopy %OEMFOLDER%\$1\* Z:\ /cherkyi)
    
    If you did it without the script, it's much simpler, but it won't ask the user and it won't auto-detect the directory. It would work something like this:
    Code:
    rem (replace D: with the same drive letter that the install.wim exists)
    xcopy D:\Sources\$OEM$\$$\* Z:\Windows\ /cherkyi
    xcopy D:\Sources\$OEM$\$1\* Z:\ /cherkyi
    
     
  2. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
    Do you do this before applying the image?
     
  3. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    It might give errors if you try to do it before applying the image. I've never tried. I always copy the files after applying the image. DISM can give errors if the partition isn't empty I believe.
     
  4. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
    the second line is without Z:\Windows\ /cherkyi

    Autounattend.xml

    to put this one would be.
    xcopy Y:\windows\Autounattend.xml\* Z:\Windows\ /cherkyi
     
  5. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    On the recovery partition, it's complicated by the fact that you need a winrecfg.exe and winrecfg.exe.mui in the corresponding folder structure. For example, I use an en-us version, so I have x86 and x64 versions of winrecfg.exe in my DASBIN folder, but I also have winrecfg.exe.mui files in their en-us subfolders. If you wanted to use pt-br versions, you would need to download the Windows ADK for the version you wanted to use. If I recall correctly, I am using a basic one from the Windows 10 ADK from 2019. Windows 7 doesn't natively support UEFI and doesn't enable recovery partitions by default. Everything from Windows 8 and above should work fine with a normal Windows 10 winrecfg.exe and mui file.
     
  6. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
    can't I just point to my folder in the iso I'm going to use? where is it in iso?
     
  7. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    The first part is intentional. $1 goes to system root Z:\
    $$ goes to Z:\Windows

    xcopy [source file(s)] [destination location] /[arguments]
     
  8. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
  9. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
    xcopy Y:\windows\Autounattend.xml Z:\Windows\ /c /h /r /k /y
     
  10. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
    I have Windows ADK.
    How would I have to apply WinRE to diskpart? and autounattend.xml, how do I copy it?
     
  11. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    No that is not correct because your ISO/USB wouldn't have a windows directory. It would have a sources directory. I'll help you out in a bit but I need to eat lunch.
     
  12. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    You have to get the winpe environment tools downloaded like dism, winrecfg etc. I forget exactly what it is called.
     
  13. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
    yes there is because it is a WinPE? the iso is inside the Windows folder, so sources is inside the Windows folder ex: dism /get-wiminfo /wimfile:Y:\windows\sources\Install.swm
     
  14. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    Oh, you're thinking of the ramdrive boot version of windows and not the actual windows setup DVD/USB.
    The ramdrive is always X:
    The files that exist on the ram drive are the files that are in the boot.wim bootable index (usually index 2)

    As far as unattend.xml or autounattend.xml, I'm not entirely sure. What I'm reading is that it should be copied into Z:\windows\Panther
    I don't actually use them, but you can check out this MS article: https://learn.microsoft.com/pt-br/w...=windows-11#implicit-answer-file-search-order
     
  15. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
    that way?
    xcopy Y:\windows\Panther\Autounattend.xml\* Z:\windows\ /cherkyi
     
  16. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
     
  17. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    No it would be like
    xcopy y:\sources\autounattend.xml z:\windows\panther\ /cherkyi
     
  18. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    #378 murphy78, May 20, 2026
    Last edited: May 20, 2026
    (OP)
    @fabricio simoes
    When you boot into a DVD or USB, it copies what is on the boot.wim bootable index into a ramdrive labeled X:
    It acts as a small version of the windows operating system or Preinstallation Environment (PE)
    You can even copy files onto the boot index of the boot.wim by mounting it and unmounting it and /commit the changes. This is how we copy the files onto

    If you look at the add-Diskpart_Apply_Image_Tool_murphy78_custom_v1.3.3.cmd script, we use wimlib-imagex.exe because it's easier and cleaner than dism, but you can use dism.
    Here are the relevant portions from the script:

    Code:
    :: Detect OS Architecture
    if %processor_architecture% == AMD64 (set arch=x64) else (set arch=x86)
    
    if %arch%==x86 (
      set _wimlib="bin\wimlib-imagex.exe"
      set "xOS=x86"
    ) else (
      set _wimlib="bin\bin64\wimlib-imagex.exe"
      set "xOS=amd64"
    )
    
    Set DPFOLDER=murphy78-DiskPart-Apply-v1.5
    Set BOOTWIMINDEX=2
    
    echo.
    echo Adding Murphy78 Diskpart and Apply Image Script To Boot.wim...
    echo.
    if not exist Work\sources\boot.wim goto :murphydualboot
    %_wimlib% update Work\sources\boot.wim %BOOTWIMINDEX% --command "add '%DPFOLDER%\%warch%\' '\'"
    %_wimlib% optimize "WORK\Sources\boot.wim" --recompress&goto :startwinpeshl
    :murphydualboot
    %_wimlib% update Work\x64\sources\boot.wim %BOOTWIMINDEX% --command "add '%DPFOLDER%\x64\' '\'"
    %_wimlib% optimize "WORK\x64\Sources\boot.wim" --recompress
    %_wimlib% update Work\x86\sources\boot.wim %BOOTWIMINDEX% --command "add '%DPFOLDER%\x86\' '\'"
    %_wimlib% optimize "WORK\x86\Sources\boot.wim" --recompress
    
    As you can see it calls the exe to UPDATE the boot.wim 's boot index using the command to ADD files
    Then it runs the same exe but with OPTIMIZE boot.wim and RECOMPRESS argument.
    This is all BEFORE you ever make an ISO or USB

    Without all of the scripting it would look something like:
    Code:
    c:\work\wimlib-imagex.exe update "c:\work\win10iso\sources\boot.wim" 2 --command "add 'c:\work\myextrafiles\' '\'"
    c:\work\wimlib-imagex.exe optimize "c:\work\win10iso\sources\boot.wim" --recompress
    
     
  19. fabricio simoes

    fabricio simoes MDL Senior Member

    Dec 17, 2020
    331
    90
    10
    #379 fabricio simoes, May 20, 2026
    Last edited: May 20, 2026
    How do you make it so that only the index appears without descriptions so that only the index is the same as the script?
     

    Attached Files:

  20. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,466
    11,872
    240
    I'm not sure what are you asking. If you only want a single index for the install.wim, you have to export it to a new install.wim.
    If you just want to have the autounattend.xml match the install.wim, you can change the numbers on the xml file using a text editor.