Use Muliple Autounattend.xml for EFI or MBR Windows installation

Discussion in 'Scripting' started by Chibi ANUBIS, Jun 29, 2016.

  1. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    #1 Chibi ANUBIS, Jun 29, 2016
    Last edited: Oct 15, 2018
    Updated 02/12/2017 !
    Is the setup for recovery by AnarethoS for Windows 10, is now possible to use two unattend for recovery partition :clap:

    If you looking for Windows 7 is here

    Needed :
    OEM Recovery Partition Creator for Windows 7/8/10

    Reference :
    $OEM$ Folder Creation DVD

    Indeed it is an "smart" script that identifies whether it should start the unattend files for MBR or EFI, I'll explain here, I used the folder "Windows 10 Recovery". Work also for Windows 7, 8, 8.1.

    Then you create winpeshl.ini and install.cmd

    winpeshl.ini
    Code:
    [LaunchApps]
    %SYSTEMDRIVE%\windows\system32\install.cmd
    install.cmd
    Code:
    @echo off
    SetLocal EnableDelayedExpansion
    
    FOR %%i IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\efi.xml SET install=%%i:
    
    :Lastly do the UEFI detection
    :Check whether user has booted with UEFI or BIOS and set UEFI=1 if UEFI
    wpeutil UpdateBootInfo
    for /f "tokens=2* delims=     " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B
    :: Note: delims is a TAB followed by a space.
    if !Firmware!==0x1 set UEFI=0
    if !Firmware!==0x2 set UEFI=1
    
    if !UEFI! EQU 1 (
    %install%\setup.exe /unattend:%install%\efi.xml /m:%install%\recovery\efi
    ) ELSE (
    %install%\setup.exe /unattend:%install%\mbr.xml /m:%install%\recovery\mbr
    )
    exit
    (In this script I search "efi.xml" on DVD root to assign the correct drive letter in the script)

    winpeshl.ini and install.cmd must be integrated into the boot.wim index 2 with dism in "Windows\System32" for install.cmd be executed since the beginning of the installation.
    Code:
    Dism /mount-wim /wimfile:C:\Extract\boot.wim /index:2 /mountdir:C:\mount
    
    Copy the install.cmd and the winpeshl.ini in "C:\mount\Windows\System32", rewrite winpreshl.ini.
    Code:
    Dism /unmount-wim /mountdir:C:\mount /commit
    
    At the root of the ISO I put the XML files that I renamed MBR and EFI. In the Recovery folder I create two folders: MBR and EFI. And I create inside a folder "$1" for Windows to copy the root of the system partition the recovery folder of AnarethoS project so it gives this: "$1\Recovery", the OOBE.cmd must give the attribut for the Recovery folder in system partition, that I already prepared for the recovery, that is to say to put the files in the folder "Settings" in "OEM" and copy "ScanState".

    OOBE.cmd
    Code:
    ATTRIB -S -R -H C:\Recovery
    ATTRIB -S -R -H C:\Recovery /S
    icacls C:\Recovery /reset /T /C
    icacls C:\Recovery /inheritance:r /grant:r SYSTEM:(OI)(CI)(F) /grant:r *S-1-5-32-544:(OI)(CI)(F) /grant:r *S-1-5-32-545:(OI)(CI)(RX) /C
    ATTRIB +S +H C:\Recovery
    RMDIR /S /Q "%WINDIR%\Setup\Scripts"
    exit
    
    I create also a cmd that I put in root for my iso for run the Recovery when I finished to install driver and software. Because the Recovery folder was hidden.

    sysprep.cmd
    Code:
    start "Sysprep" "C:\Recovery\OEM\Sysprep.cmd"
    exit
    
    Architecture of the ISO :
    Code:
    ISO\recovery\mbr\$1\Recovery
    ISO\recovery\efi\$1\Recovery
    ISO\recovery\mbr\$$\Setup\Script\OOBE.cmd
    ISO\recovery\efi\$$\Setup\Script\OOBE.cmd
    ISO\mbr.xml
    ISO\efi.xml
    ISO\sysprep.cmd
    Suffice to install software and driver and then launch "Sysprep.cmd" and everything is ready :)

    I made this project to save on DVD since I was four with two more the recovery architecture or two if I make an AIO, now one is enough, and even more by USB it works it's really cool !

    I hope I was clear enough if need does not hesitate to come back to ask me anything at all, I can even upload my project for you that you will take a look ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. wk-952

    wk-952 MDL Member

    Sep 2, 2012
    115
    285
    10
    #2 wk-952, Jun 29, 2016
    Last edited by a moderator: Apr 20, 2017
    This is not a solution to your problem but something worth mentioning.
    You are using the exclamation mark to expand variables (delayed variable expansion):
    Code:
    if !Firmware!==0x1 set UEFI=0
    if !Firmware!==0x2 set UEFI=1
    if !UEFI! EQU 1 (
    
    But you don't seem to enable delayed variable expansion at the beginning of your script after the line "@echo off"
    so you're comparing the string "!UEFI!" (literally as it is like that) against the number one, which of course will always be false.

    As for your original problem, are you sure the file "MBR.xml" exists in the root directory of the setup ?
     
  3. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    #3 Chibi ANUBIS, Jun 29, 2016
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thank you wk-952 :)

    My file xml exist in the root of directory but the setup not found "X:\MBR.xml not found" I test on VMware.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    #4 Chibi ANUBIS, Jun 29, 2016
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I updated :
    Code:
    @echo off
    SetLocal EnableDelayedExpansion
    
    FOR %%i IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\setup.exe SET Install=%%i:
    
    :Lastly do the UEFI detection
    :Check whether user has booted with UEFI or BIOS and set UEFI=1 if UEFI
    wpeutil UpdateBootInfo
    for /f "tokens=2* delims=     " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B
    :: Note: delims is a TAB followed by a space.
    if !Firmware!==0x1 set UEFI=0
    if !Firmware!==0x2 set UEFI=1
    
    if !UEFI! EQU 1 ( 
    %install%\setup.exe /unattend:%install%\EFI.xml /m:%install%\sources\EFI
    ) ELSE (
    %install%\setup.exe /unattend:%install%\MBR.xml /m:%install%\sources\MBR
    )
    exit
    And is the same error :(
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    [​IMG][​IMG]
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    IS FIXED !
    I missed he exist two setup.exe ... :eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. wk-952

    wk-952 MDL Member

    Sep 2, 2012
    115
    285
    10
    Could you please explain further what was the issue ?
    I'm very curious about this.
     
  8. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30

    I realized after the boot.wim back that there were also a setup.exe, so logically the script that had the search will take this one and not that of the DVD and then can not find the xml file as it is in the DVD and not the boot.wim.

    To solve the problem I ask him to look for another file that does not exist in the boot.wim but only on DVD and there attribute the correct drive letter to start the xml file.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. mehdibleu

    mehdibleu MDL Expert

    Jun 14, 2017
    1,009
    212
    60
    #9 mehdibleu, Aug 21, 2017
    Last edited: Aug 21, 2017
    thank you for that script, it is a really smart script that allows to boot either from BIOS(MBR) or EFI according to user's bios configuration.
    I've tested it and it works great.

    And as i see but i'm not sure about this, you adjusted this script to be able to save time as you can directly lauch "sysprep.cmd" to capture the image after the installation of win10 is finished.

    if i'm correct, you tested this script on win10 configuration but i suppose that you can use it for all other windows versions.

    So back to the point i've just mentionned above, what about "install - windows 10.cmd" that you normally have to launch before "sysprep.cmd" in @AnarethoS script project ?
    did you adjust your script to be able to skip "install - windows 10.cmd" and run only "sysprep.cmd" ?
    or do you have to run "install - windows 10.cmd" as well before "sysprep.cmd" with your script to be able to make this work ?

    in other words, is it necessary to lauch "install - windows 10.cmd" just before running "sysprep.cmd" with your script ? or it is not necessary to launch "install - windows 10.cmd" anymore using your script ?
     
  10. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    Thank you I'm glad to see your comment :)
    My script works for all Windows, it is possible to remove "/m:%install%\sources\EFI" If you do not need to move a Recovery folder. Indeed with this method it is not necessary to run "Install - Windows 10.cmd" as the folder in question is already installed, you just have to put "ResetConfig.xml" of the Settings folder in the Recovery OEM folder before launching Sysprep.exe. The only difference is that the Recovery folder will not have the assignments that it gives "Install - Windows 10.cmd":
    Code:
    ATTRIB -S -R -H C:\Recovery
    ATTRIB -S -R -H C:\Recovery /S
    icacls C:\Recovery /reset /T /C
    icacls C:\Recovery /inheritance:r /grant:r SYSTEM:(OI)(CI)(F) /grant:r *S-1-5-32-544:(OI)(CI)(F) /grant:r *S-1-5-32-545:(OI)(CI)(RX) /C
    ATTRIB +S +H C:\Recovery
    
    VoilĂ  ! :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. mehdibleu

    mehdibleu MDL Expert

    Jun 14, 2017
    1,009
    212
    60
    thank you for the reply but i didn't get the last sentence , what do you mean by "The only difference is that the Recovery folder will not have the assignments that it gives "Install - Windows 10.cmd".
    i see that you speak french, that's good news for me as i speak french as well, so if you could explain what you meant in this last sentence in french, that would be nice.:)
     
  12. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    In French is only message private please :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. amulder31

    amulder31 MDL Novice

    Apr 30, 2017
    2
    0
    0
    Hello Chibi Anubis,
    I would be interested in your script edit as you did I try to do it without success it would be very nice to share it I'm also in France
    In advance thank you very much for your sharing
    cordially
    Amulder
     
  14. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    #14 Chibi ANUBIS, Dec 2, 2017
    Last edited: Dec 24, 2017
    (OP)
    Hello amulder31,
    I haven't files, is simply follow the post and download the OEM project by AnarethoS, It must be prepared before, I updated my thread, please tell me if you understand the process :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. amulder31

    amulder31 MDL Novice

    Apr 30, 2017
    2
    0
    0
    Hello Chibi ANUBIS,
    Thank you very much I will try with your script good Sunday
     
  16. pacoolio

    pacoolio MDL Junior Member

    Jun 10, 2009
    95
    85
    0
    Is there an easier method to integrate all of this script in Windows 7 OEM ?
     
  17. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    753
    421
    30
    Hello ! For Windows 7 you just need to prepare the xml for partitioning your hard drive :

    ONLY FOR x64 !
    Because x86 don't run EFI, just put the MBR autounattend

    winpeshl.ini
    Code:
    [LaunchApps]
    %SYSTEMDRIVE%\windows\system32\install.cmd
    install.cmd
    Code:
    @echo off
    SetLocal EnableDelayedExpansion
    
    FOR %%i IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\efi.xml SET install=%%i:
    
    :Lastly do the UEFI detection
    :Check whether user has booted with UEFI or BIOS and set UEFI=1 if UEFI
    wpeutil UpdateBootInfo
    for /f "tokens=2* delims=     " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B
    :: Note: delims is a TAB followed by a space.
    if !Firmware!==0x1 set UEFI=0
    if !Firmware!==0x2 set UEFI=1
    
    if !UEFI! EQU 1 (
    %install%\setup.exe /unattend:%install%\efi.xml
    ) ELSE (
    %install%\setup.exe /unattend:%install%\mbr.xml
    )
    exit

    And Copy/Paste the Recovery folder in the root of your ISO
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...