[BATCH] [DISKPART][DISM] OS installation using WinPE

Discussion in 'Scripting' started by Humphrey, Dec 12, 2013.

  1. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #1 Humphrey, Dec 12, 2013
    Last edited by a moderator: Apr 20, 2017
    Creating a batch to run diskpart from WindowsPE.

    DiskPartition.CMD
    Auto starts or is ran from another auto start. IDK yet, this is beta as beta can be.
    Code:
    :: Create Partition
    @ECHO OFF
    ::SETUP
    TITLE Partition Creation!
    SetLocal EnableDelayedExpansion
    ECHO.
    choice /C MG /M "Create [M]BR or [G]PT partition table?:"
    if !ERRORLEVEL! EQU 1 CLS & GOTO :MBR
    if !ERRORLEVEL! EQU 2 CLS & GOTO :GPT
    PAUSE & GOTO :EOF
    ::MBR Partition
    :MBR
    DISKPART /S MBR.txt
    exit
    ::GPT Partition
    :GPT
    DISKPART /S GPT.txt
    EXIT
    
    MBR.TXT

    I think this bit is fine. I used it recently to create my partitions manually when applying an image to my HDD.
    Code:
    select disk 0
    clean
    create partition primary size=300
    format quick fs=ntfs label="System"
    assign letter="S"
    active
    create partition primary
    format quick fs=ntfs label="Windows"
    assign letter="W"
    
    GPT.TXT

    I have no idea if this is right. Any that has experience with creating GPT partitions with diskpart please chime in. Also, what does it take to then apply an image to this partition? Just apply it or does it need more for it to be GPT/uEFI?
    Code:
    select disk 0
    clean
    convert gpt
    format quick fs=fat32 label="System"
    assign letter="S"
    create partition msr size=128
    create partition primary
    format quick fs=ntfs label="Windows"
    assign letter="W"
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    So I started a VM(ware) and set it to uefi.

    I booted to a Windows setup, accessed the command prompt and used the diskpart to command a gpt into existence. So I got that and then I set the bcdedit/bcdboot to make the boot files but that didn't work. Maybe I am doing something wrong.

    Any help would be awesome.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #3 Humphrey, Dec 13, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I have moved on from fixing GPT right now. Here is the batch file that I will have run automatically in Windows PE when it starts.

    This is unfinished of course.
    (Still looking for how to get GPT/uEFI to partition/boot to work.)

    OLD
    Code:
    :: Create Partition
    @ECHO OFF
    ::SETUP
    SetLocal EnableDelayedExpansion
    SET IMGDIR=.\Images\
    :Main
    ::Main Menu / OS Selection
    TITLE Select Which Windows OS To Install
    ECHO.
    ECHO. Select which Windows version/architecture to install.
    ECHO.
    ECHO. 1] Windows Vista
    ECHO. 2] Windows 7
    ECHO. 3] Windows 8
    ECHO. 4] Windows 8.1
    
    ECHO.
    choice /C 1234 /N /M "What version of windows?:"
    if !ERRORLEVEL! EQU 1 SET IMGFILE=\v& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :WinV
    if !ERRORLEVEL! EQU 2 SET IMGFILE=\7& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win7
    if !ERRORLEVEL! EQU 3 SET IMGFILE=\8& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win8
    if !ERRORLEVEL! EQU 4 SET IMGFILE=\81& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win8
    
    
    :WinV
    ::WinVista
    TITLE Windows Vista
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Ultimate 
    ECHO.
    choice /C 123 /M "What edition to install?:"
    if !ERRORLEVEL! EQU 1 SET IMGINDX=2
    if !ERRORLEVEL! EQU 2 SET IMGINDX=3
    if !ERRORLEVEL! EQU 3 SET IMGINDX=4
    GOTO :Partitioning
    
    :Win7
    ::Win7
    TITLE Wndows 7 x64
    ECHO. 
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Professional
    ECHO. 4] Ultimate 
    ECHO.
    choice /C 1234 /M "What edition to install?:"
    if !ERRORLEVEL! EQU 1 SET IMGINDX=1
    if !ERRORLEVEL! EQU 2 SET IMGINDX=2
    if !ERRORLEVEL! EQU 4 SET IMGINDX=3
    if !ERRORLEVEL! EQU 5 SET IMGINDX=4
    GOTO :Partitioning
    
    :Win8
    ::Win8/1
    TITLE Wndows 8 and 8.1 
    ECHO. 
    ECHO. 1] Core
    ECHO. 2] Professional
    ECHO.
    choice /C 12 /M "What edition to install?:"
    if !ERRORLEVEL! EQU 1 SET IMGINDX=2
    if !ERRORLEVEL! EQU 2 SET IMGINDX=1
    GOTO :Partitioning
    
    
    
    :Partitioning 
    CLS
    ::Partitioning Menu
    ECHO.
    choice /C MG /M "Create [M]BR or [G]PT partition table?:"
    if !ERRORLEVEL! EQU 1 CLS & GOTO :MBR
    if !ERRORLEVEL! EQU 2 CLS & GOTO :GPT
    PAUSE & GOTO :EOF
    
    :MBR
    ::Creates MBR partition for Bios/uEFI
    ECHO.
    DISKPART /S MBR.txt
    DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
    ping -n 2 localhost
    bcdboot W:\Windows /l EN-US
    bcdboot W:\Windows /s S: /f ALL
    Pause & Goto :MAIN
    :GPT
    ::Creates GPT partition for uEFI
    ECHO.
    ECHO.Not Available.
    ECHO.Use MBR or manaully create the GPT/Boot settings.
    ECHO.& PAUSE & CLS & GOTO :Main
    DISKPART /S GPT.txt
    DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
    ping -n 2 localhost
    bcdboot W:\Windows /l EN-US
    bcdboot c:\windows /s h: /f UEFI
    

    NEW
    Code:
    :: InstallOS.CMD v0.8
    :: Written by: Humphrey
    ::
    :: Runs from Windows PE to create partitions, apply a Windows image file, and setup the boot record.
    @ECHO OFF
    ::SETUP
    SetLocal EnableDelayedExpansion
    SET IMGDIR=.\Images\
    CD /D %~dp0
    :Main
    ::Main Menu / OS Selection
    TITLE Select Which Windows OS To Install
    ECHO.
    ECHO. Select which Windows version to install.
    ECHO.
    ECHO. 1] Windows Vista
    ECHO. 2] Windows 7
    ECHO. 3] Windows 8
    ECHO. 4] Windows 8.1
    ECHO.
    choice /C 1234 /N /M "What version of windows?:"
    if !ERRORLEVEL! EQU 1 SET IMGFILE=\v& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :WinV
    if !ERRORLEVEL! EQU 2 SET IMGFILE=\7& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win7
    if !ERRORLEVEL! EQU 3 SET IMGFILE=\8& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win8
    if !ERRORLEVEL! EQU 4 SET IMGFILE=\81& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win8
    :WinV
    ::WinVista
    IF '!ARCH!'=='' GOTO MAIN
    TITLE Windows Vista !ARCH!
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Ultimate 
    ECHO.
    choice /C 123 /N /M "What edition to install?:" 
    if !ERRORLEVEL! EQU 1 SET IMGINDX=2 & SET CHK= Windows Vista - Home Basic
    if !ERRORLEVEL! EQU 2 SET IMGINDX=3 & SET CHK= Windows Vista - Home Premium
    if !ERRORLEVEL! EQU 3 SET IMGINDX=4 & SET CHK= Windows Vista - Ultimate
    GOTO :CHK
    :Win7
    ::Win7
    IF '!ARCH!'=='' GOTO MAIN
    TITLE Wndows 7 !ARCH!
    ECHO. 
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Professional
    ECHO. 4] Ultimate 
    ECHO.
    choice /C 1234 /N /M "What edition to install?:"
    if !ERRORLEVEL! EQU 1 SET IMGINDX=1 & SET CHK= Windows 7 - Home Basic
    if !ERRORLEVEL! EQU 2 SET IMGINDX=2 & SET CHK= Windows 7 - Home Premium
    if !ERRORLEVEL! EQU 3 SET IMGINDX=3 & SET CHK= Windows 7 - Home Professional
    if !ERRORLEVEL! EQU 4 SET IMGINDX=4 & SET CHK= Windows 7 - Home Ultimate
    GOTO :CHK
    :Win8
    ::Win8/1
    IF '!ARCH!'=='' GOTO MAIN
    TITLE Wndows 8 !ARCH! (or) 8.1 !ARCH!
    ECHO. 
    ECHO. 1] Core
    ECHO. 2] Professional
    ECHO.
    choice /C 12 /N /M "What edition to install?:"
    if !ERRORLEVEL! EQU 1 SET IMGINDX=2 & SET CHK= Windows 8(.1) - Core
    if !ERRORLEVEL! EQU 2 SET IMGINDX=1 & SET CHK= Windows 8(.1) - Professional
    GOTO :CHK
    :CHK
    ::Install OS Check
    ECHO.
    ECHO.You are about to start the installation of: !CHK! !ARCH!
    ECHO.
    choice /C YN /N /M "Continue?:"
    if !ERRORLEVEL! EQU 1 GOTO :Partitioning
    if !ERRORLEVEL! EQU 2 SET ARCH=&SET IMGFILE=&SET IMGINDX=& GOTO :MAIN
    :Partitioning 
    ::Partitioning Menu
    choice /C MG /M "Create [M]BR or [G]PT partition table?: "
    if !ERRORLEVEL! EQU 1 CLS & GOTO :MBR
    if !ERRORLEVEL! EQU 2 CLS & GOTO :GPT
    PAUSE & GOTO :EOF
    :MBR
    ::Creates MBR partition for Bios/uEFI
    ECHO.
    DISKPART /S MBR.txt
    DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
    ping -n 2 localhost
    bcdboot W:\Windows /l EN-US
    bcdboot W:\Windows /s S: /f ALL
    Start CMD & EXIT
    :GPT
    ::Creates GPT partition for uEFI
    ECHO.
    ECHO.Not Available.
    ECHO.Use MBR or manaully create the GPT/Boot settings.
    ECHO.& PAUSE & CLS & GOTO :Main
    DISKPART /S GPT.txt
    DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
    ping -n 2 localhost
    bcdboot W:\Windows /l EN-US
    bcdboot c:\windows /s h: /f UEFI
    Start CMD & EXIT
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #4 Humphrey, Dec 14, 2013
    Last edited: Dec 17, 2013
    (OP)
    Tested the batch file in a booted setup.
    Started a VM.
    Booted to Windows install setup.
    Accessed the command prompt.
    Ran the batch file.
    Error'ed.
    Seems I needed to add choice.exe to the folder for it to work- so I did.
    Seems choice does not work in WinPE.. I wonder why I thought it did.. :/
    Seems it does work in WinPE. Wish it would make up its damned mind.
    Ran the batch file.
    Ran and installed Windows Vista.

    So it is working.
    Now I need to neatly code in a choice.exe location for WindowsPE or just bundle it along with the batch file.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #5 Humphrey, Dec 15, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Updated the installer script.

    Code:
    :: InstallOS.CMD v0.9
    :: Written by: Humphrey
    ::
    :: Runs from Windows PE to create partitions, apply a Windows image file, and setup the boot record.
    :: 
    @ECHO OFF
    ::SETUP
    SetLocal EnableDelayedExpansion
    FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET NowT=%%A & FOR /F "TOKENS=*" %%A IN ('DATE/T') DO SET NowD=%%A
    SET BIN=.\bin\
    SET IMGDIR=!BIN!Images\
    SET LOG=!BIN!Logs\Output.log
    CD /D %~dp0
    :Main
    ::Main Menu / OS Selection
    TITLE Humphreys OS Installer
    ECHO.
    ECHO. Select which Windows version to install.
    ECHO.
    ECHO. 1] Windows Vista
    ECHO. 2] Windows 7
    ECHO. 3] Windows 8
    ECHO.
    choice /C 1234 /N /M "What version of windows?:"
    SET FWD=!ERRORLEVEL!
    IF !ERRORLEVEL! EQU 4 START CMD &EXIT
    IF NOT !ERRORLEVEL! EQU 3 GOTO :ARCHSEL
    :: Win8/1
    ECHO.
    ECHO. 1] Windows 8
    ECHO.
    ECHO. 2] Windows 8.1
    ECHO.
    choice /C 12 /N /M "Which to install?: "
    if !ERRORLEVEL! EQU 1 SET IMGFILE=\8& SET CHK1=Windows 8&CLS
    if !ERRORLEVEL! EQU 2 SET IMGFILE=\81& SET CHK1=Windows 8.1&CLS
    :ARCHSEL
    :: Architecture Menu
    ECHO.
    ECHO. 1] x32 (x86)
    ECHO.
    ECHO. 2] x64
    ECHO.
    choice /C 12 /N /M "Which architecture?:"
    IF !ERRORLEVEL! EQU 1 SET Arch=x32
    IF !ERRORLEVEL! EQU 2 SET Arch=x64
    ::Partitioning Menu
    ECHO.
    choice /C MG /M "Create MBR or GPT partition table?: "
    if !ERRORLEVEL! EQU 1 CLS & SET PART=MBR& SET BOOT=bcdboot W:\Windows /s S: /f ALL
    if !ERRORLEVEL! EQU 2 CLS & SET PART=GPT& SET BOOT=bcdboot W:\windows /s S: /f UEFI
    CALL :!FWD!
    :1
    ::WinVista
    SET IMGFILE=\v
    ECHO.
    ECHO. Windows Vista (!ARCH!)
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Ultimate 
    ECHO.
    choice /C 123 /N /M "What edition to install?:" 
    if !ERRORLEVEL! EQU 1 SET IMGINDX=2 & SET CHK= Windows Vista Home Basic
    if !ERRORLEVEL! EQU 2 SET IMGINDX=3 & SET CHK= Windows Vista Home Premium
    if !ERRORLEVEL! EQU 3 SET IMGINDX=4 & SET CHK= Windows Vista Ultimate
    GOTO :CHK
    :2
    ::Win7
    SET IMGFILE=\7
    ECHO.
    ECHO. Windows 7 (!ARCH!)
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Professional
    ECHO. 4] Ultimate 
    ECHO.
    choice /C 1234 /N /M "What edition to install?:"
    if !ERRORLEVEL! EQU 1 SET IMGINDX=1 & SET CHK= Windows 7 Home Basic
    if !ERRORLEVEL! EQU 2 SET IMGINDX=2 & SET CHK= Windows 7 Home Premium
    if !ERRORLEVEL! EQU 3 SET IMGINDX=3 & SET CHK= Windows 7 Home Professional
    if !ERRORLEVEL! EQU 4 SET IMGINDX=4 & SET CHK= Windows 7 Ultimate
    GOTO :CHK
    :3
    ECHO.
    ECHO. !CHK1! (!ARCH!)
    ECHO. 
    ECHO. 1] Core
    ECHO.
    ECHO. 2] Professional
    ECHO.
    choice /C 12 /N /M "What edition to install?:"
    if !ERRORLEVEL! EQU 1 SET IMGINDX=2 & SET CHK= Core&CLS
    if !ERRORLEVEL! EQU 2 SET IMGINDX=1 & SET CHK= Professional&CLS
    GOTO :CHK
    :CHK
    ::Install OS Check
    TITLE Install Check
    ECHO.
    ECHO.Start installation of: !CHK1!!CHK! (!ARCH!)
    ECHO.
    choice /C YN /M "Continue"
    if !ERRORLEVEL! EQU 1 CLS & GOTO :APPLYSETTINGS
    if !ERRORLEVEL! EQU 2 SET ARCH=&SET IMGFILE=&SET IMGINDX=& CLS & GOTO :MAIN
    :APPLYSETTINGS
    :: Applies image file and creates the partitions tables and boot settings. 
    ECHO.
    DISKPART /S !BIN!!PART!.txt
    DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
    ping -n 2 localhost
    bcdboot W:\Windows /l EN-US
    !BOOT!
    :LOG
    :: Outputs log of completed install. 
    ECHO.Installed !CHK1!!CHK! !ARCH! on !NowD! @ !NowT!!LOG!
    Start CMD & EXIT
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,493
    633
    60
    #6 Flipp3r, Dec 15, 2013
    Last edited by a moderator: Apr 20, 2017
    You can detect what mode you've booted into.
    For my startnet.cmd I have:
    Code:
    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 echo BIOS >X:\BIOS
    if %Firmware%==0x2 echo UEFI >X:\UEFI
    So in my Install.cmd I can:
    Code:
    IF EXIST X:\BIOS set Platform=BIOS
    IF EXIST X:\UEFI set Platform=UEFI
    DiskPart /s %PTH%Files\%Platform%-CreatePartitions.txt
    \Windows81.64\setup /unattend:%PTH%Files\%Platform%-Unattend.xml
    As you can see this is for Windows 8.1 only with WinPE5. I only do the mode check once & any batch files I run just check for x:\bios or x:\uefi (which is always there if booting from winpe)...

    My UEFI-CreatePartitions.txt file is:
    Code:
    sel dis 0
    cle
    con gpt
    rem == 1. Windows RE tools partition ===============
    cre par pri size=350
    for fs=ntfs label="Windows RE tools" quick
    set id="DE94BBA4-06D1-4D40-A16A-BFD50179D6AC"
    gpt attributes=0x8000000000000001
    assign letter="T"
    rem == 2. System partition =========================
    cre par efi size=100
    rem    ** NOTE: For Advanced Format 4Kn drives, change this value to size = 260 ** 
    for quick fs=fat32 label="System"
    assign letter="S"
    rem == 3. Microsoft Reserved (MSR) partition =======
    cre par msr size=128
    rem == 4. Windows partition ========================
    cre par pri
    for quick fs=ntfs label="Windows"
    assign letter="W"
    lis vol
    exit
    WinPE also has the enviroment variable %processor_architecture%. My usb key has a choice of booting 32 or 64bit WinPe.
    You can also just:
    Code:
    if %processor_architecture% == AMD64 \Source.x64\setup /unattend:%PTH%Files\Unattend-BIOS.xml
    if %processor_architecture% == x86 \Source.x86\setup /unattend:%PTH%Files\Unattend-BIOS.xml
     
  7. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,493
    633
    60
    #7 Flipp3r, Dec 15, 2013
    Last edited by a moderator: Apr 20, 2017
    I had a look at one of my old keys. I used "set /p" command instead of choice:
    Code:
    :Menu
    cls
    echo.
    echo Installation Mode:
    echo =============
    echo.
    echo 1) Install Windows 8 %Arc% (Bios Mode)
    echo 2) Install Windows 8 %Arc% (Bios Mode) with a Recovery Partition
    echo 3) Exit
    echo.
    set /p InstallMode=Type option:
    if "%InstallMode%"=="1" goto BiosNoRE
    if "%InstallMode%"=="2" goto BiosWinRE
    if "%InstallMode%"=="3" goto EOF
    goto Menu
     
  8. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    Might as well post the whole batch :p

    I was in the middle of replying when the thread updated..
    I like how you've got the option for WindowsRE or not.
    I tested in a boot environment which I assume is similar to WindowsPE and it couldn't find Choice.exe so I decided to bundle it, not sure if I will keep it.

    So about uEFI partitioning. I want to be able to do it for Windows Vista, 7, and 8(.01) This bit you've posted will support those?
    I will be using Windows 8.1 ADK WindowsPE for this.
    It is possible to pass along a varible in WindowsPE right? Id like to not have to create a tag file for the firmware selection.

    I doubt I will need windows PE x64 but it would be nice if when i booted it checked the architecture and then booted the corresponding WinPE arch.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,493
    633
    60
    #9 Flipp3r, Dec 16, 2013
    Last edited by a moderator: Apr 20, 2017
    That was from an old key I used to use. With my current setup I've tried to "dumb" things down by keeping it simple.
    Since the recovery image (install.wim/esd) is in the last partition, this can be created on the fly just before sysprep.
    UEFI Setup.png
    http://technet.microsoft.com/en-us/library/hh825212.aspx
    The UEFI partitioning I did above should be fine for all OS. The 1st Tools partition is optional but you will find that if it exists, Windows 8.1 will automatically use it & place winre.wim into it.

    With this type of partition layout, the end user can use the tools provided my MS to create a recovery USB.
    Code:
    C:\Windows\System32\RecoveryDrive.exe
    Once this backup is created, there is an option to delete the recovery from the drive.
    Handy if you only have a small SSD...
     
  10. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #10 Humphrey, Dec 17, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Hey. I was looking around and found a way to pass along the firmware that is detected.


    Code:
    StartNet.CMD
    @ECHO OFF
    :: StartNet.CMD 
    :: Placed in System32 of WinPE
    
    wpeutil UpdateBootInfo
    
    for /f "tokens=2* delims=     " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET DetectFirm=%%B
    :: Note: delims is a TAB followed by a space.
    
    if %DetectFirm%==0x1 SET FIRMWARE=BIOS
    if %DetectFirm%==0x2 SET FIRMWARE=UEFI
    
    :: Call or Start - Passes along firmware variable. 
    start InstallOS.CMD %FIRMWARE%
    
    InstallOS.cmd
    Code:
    @ECHO OFF
    ECHO.%FIRMWARE%
    PAUSE
    
    Useful I believe so that there isn't that bit of code creating the bios/uefi file cause I think when it is reused then it will detect both or the old one and select the wrong diskpart operation.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,493
    633
    60
    Yes, setting an enviroment variable is fine. As X: is virtual drive for PE, having temp files didn't bother me as they are gone on reboot...
     
  12. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #12 Humphrey, Dec 17, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    That is true. I am still learning how WinPE functions so I will say a lot of useless junk..

    I decided to expunge choice from the code:
    Code:
    :: InstallOS.CMD v1.0
    :: Written by: Humphrey
    ::
    :: Runs from Windows PE to create partitions, apply a Windows image file, and setup the boot record.
    :: In this version, BIN and IMAGES need to be in the same folder as InstallOS.CMD
    ::
    @ECHO OFF
    :: SETUP
    SetLocal EnableDelayedExpansion
    CD /D %~dp0
    FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET NowT=%%A & FOR /F "TOKENS=*" %%A IN ('DATE/T') DO SET NowD=%%A
    SET BIN=.\bin\& SET IMGDIR=!BIN!Images\& SET LOG=!BIN!Logs\Output.log
    :MAIN
    TITLE Humphreys OS Installer
    :: Main Menu / OS Selection
    ECHO.
    ECHO. Select which Windows version to install.
    ECHO.
    ECHO. 1] Windows Vista
    ECHO. 2] Windows 7
    ECHO. 3] Windows 8
    ECHO.
    SET /P VER=What version to install?: 
    IF "!VER!"=="" CLS & GOTO :MAIN
    SET SVER=!VER! & CLS
    :ARCHSEL
    :: Architecture Menu
    ECHO.
    ECHO. 1] x32 (x86)
    ECHO.
    ECHO. 2] x64
    ECHO.
    SET /P ARCHSEL=What architecture to install?: 
    IF "!ARCHSEL!"=="" GOTO :ARCHSEL 
    IF "!ARCHSEL!"=="1" (SET Arch=x32& CLS) else SET Arch=x64& CLS
    :PARTMENU
    :: Partitioning Menu
    ECHO.
    ECHO.!FIRMWARE! was detected on boot.
    ECHO.
    ECHO. 1] MBR BIOS
    ECHO.
    ECHO. 2] GPT uEFI
    ECHO.
    SET /P PARTITION=What parition scheme to use?: 
    IF "!PARTITION!"=="" GOTO :PARTMENU
    IF "!PARTITION!"=="1" SET PART=MBR& SET BOOT=bcdboot W:\Windows /s S: /f ALL& CLS
    IF "!PARTITION!"=="2" SET PART=GPT& SET BOOT=bcdboot W:\windows /s S: /f UEFI& CLS
    GOTO :!SVER!
    :1
    :: WinVista
    SET IMGFILE=\v
    ECHO.
    ECHO. Windows Vista (!ARCH!)
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Ultimate 
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" GOTO :1
    IF "!EDI!"=="1" SET IMGINDX=2& SET CHK= Windows Vista Home Basic& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=3& SET CHK= Windows Vista Home Premium& CLS & GOTO :CHK
    IF "!EDI!"=="3" SET IMGINDX=4& SET CHK= Windows Vista Ultimate& CLS & GOTO :CHK
    CLS & GOTO :1
    :2
    :: Win7
    SET IMGFILE=\7
    ECHO.
    ECHO. Windows 7 (!ARCH!)
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Professional
    ECHO. 4] Ultimate 
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" GOTO :2
    IF "!EDI!"=="1" SET IMGINDX=1& SET CHK= Windows 7 Home Basic& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=2& SET CHK= Windows 7 Home Premium&& CLS & GOTO :CHK
    IF "!EDI!"=="3" SET IMGINDX=3& SET CHK= Windows 7 Home Professional& CLS & GOTO :CHK
    IF "!EDI!"=="4" SET IMGINDX=4& SET CHK= Windows 7 Ultimate& CLS & GOTO :CHK
    CLS & GOTO :2
    :3
    :: Win8/1
    ECHO.
    ECHO. 1] Windows 8
    ECHO.
    ECHO. 2] Windows 8.1
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" GOTO :3
    IF "!EDI!"=="1" SET IMGFILE=\8& SET CHK1=Windows 8& CLS & GOTO :4
    IF "!EDI!"=="2" SET IMGFILE=\81& SET CHK1=Windows 8.1& CLS & GOTO :4
    CLS & GOTO :3
    :4
    ECHO.
    ECHO. !CHK1! (!ARCH!)
    ECHO. 
    ECHO. 1] Core
    ECHO.
    ECHO. 2] Professional
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" CLS & GOTO :3
    IF "!EDI!"=="1" SET IMGINDX=2 & SET CHK= Core& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=1 & SET CHK= Professional& CLS & GOTO :CHK
    CLS & GOTO :4
    :CHK
    :: Install OS Check
    TITLE Install Check
    ECHO.
    ECHO.Start installation of: !CHK1!!CHK! (!ARCH!) [!PART!]
    ECHO.
    SET /P CONT=[Y]es / [N]o: 
    IF "CONT"=="" CLS & GOTO :CHK
    IF /I "CONT"=="Y" CLS & GOTO :APPLYSETTINGS
    IF /I "CONT"=="N" SET PARTITION=& SET PART=& SET ARCHSEL=& SET EDI=& SET ARCH=& SET IMGFILE=& SET IMGINDX=& SET VER=& CLS & GOTO :MAIN
    :APPLYSETTINGS
    ECHO. 
    :: Applies image file and creates the partitions tables and boot settings. 
    DISKPART /S !BIN!!PART!.txt
    DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
    ping -n 2 localhost
    bcdboot W:\Windows /l EN-US
    !BOOT!
    :LOG
    :: Outputs log of completed install. 
    ECHO.Installed !CHK1!!CHK! !ARCH! on !NowD! @ !NowT!!LOG!
    Start CMD & EXIT
    
    

    Something is wrong with the dism part, not doing what i want it do so I am testing.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    So I fixed the DISM command. Turns out I had it looking for the wrong file.

    Anyways, now I just have to get the bcdboot command to work.
    Running from the script it doesn't work, running it by itself, does work.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #14 Humphrey, Dec 18, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    StartNet.CMD (Placed in System32 of a WinPE wim)
    Working on getting this slimmed down.
    Code:
    :: StartNet.CMD 
    :: Placed in System32 of WinPE
    
    @ECHO OFF
    
    :: Setup for InstallOS.cmd
    wpeutil UpdateBootInfo
    for /f "tokens=2* delims=     " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET DetectFirm=%%B
    :: Note: delims is a TAB followed by a space.
    if %DetectFirm%==0x1 SET FIRMWARE=BIOS
    if %DetectFirm%==0x2 SET FIRMWARE=UEFI
    
    :: Add script to detect InstallOS.cmd and then call it. 
    set drive=
    for %%a 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 (
        >nul 2>&1 dir "%%a:\installos.cmd"
        if not errorlevel 1 (
            if defined drive (
                echo more that one drive has "installos.cmd" on it!!!!!!!!
                pause
                goto :eof
            )
            set drive=%%a:\
        )
    )
    
    if defined drive (
        Start %drive%InstallOS.CMD
    ) else (
        echo no drive containing "installos.cmd" was found on this computer
        goto :eof
    )
    
    :: Future Stuff
    :EXIT
    


    InstallOS.cmd (Located in the root of the boot media, called by StartNet.cmd)

    Also located in root of the boot media
    .\BIN\
    .\BIN\Images
    .\BIN\x64
    .\BIN\x64\7x64.wim
    .\BIN\x64\81x64.wim
    .\BIN\x64\8x64.wim
    .\BIN\x64\vx64.wim
    .\BIN\x86
    .\BIN\x86\7x86.wim
    .\BIN\x86\81x86.wim
    .\BIN\x86\8x86.wim
    .\BIN\x86\vx86.wim
    .\BIN\Logs (Working on relocating these to the temp folder of the WinPE so they can actually be written and thusly, observed.)
    .\BIN\MBR.txt
    .\BIN\GPT.txt

    Code:
    :: InstallOS.CMD v1.2
    :: Written by: Humphrey
    ::
    :: Runs from Windows PE to create partitions, apply a Windows image file, and setup the boot record.
    :: In this version, BIN and IMAGES need to be in the same folder as InstallOS.CMD
    ::
    @ECHO OFF
    :: SETUP
    SetLocal EnableDelayedExpansion
    CD /D %~dp0
    FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET NowT=%%A & FOR /F "TOKENS=*" %%A IN ('DATE/T') DO SET NowD=%%A
    SET BIN=.\bin\& SET IMGDIR=!BIN!Images\& SET LOG=!BIN!Logs\Output.log
    :MAIN
    TITLE Humphreys OS Installer
    :: Main Menu / OS Selection
    ECHO.
    ECHO. Select which Windows version to install.
    ECHO.
    ECHO. 1] Windows Vista
    ECHO. 2] Windows 7
    ECHO. 3] Windows 8
    ECHO.
    SET /P VER=What version to install?: 
    IF "!VER!"=="" CLS & GOTO :MAIN
    SET SVER=!VER! & CLS
    :ARCHSEL
    :: Architecture Menu
    ECHO.
    ECHO. 1] x32 (x86)
    ECHO.
    ECHO. 2] x64
    ECHO.
    SET /P ARCHSEL=What architecture to install?: 
    IF "!ARCHSEL!"=="" GOTO :ARCHSEL 
    IF "!ARCHSEL!"=="1" (SET Arch=x86& CLS) else SET Arch=x64& CLS
    :PARTMENU
    :: Partitioning Menu
    ECHO.
    ECHO.!FIRMWARE! was detected on boot.
    ECHO.
    ECHO. 1] MBR BIOS
    ECHO.
    ECHO. 2] GPT uEFI
    ECHO.
    SET /P PARTITION=What parition scheme to use?: 
    IF "!PARTITION!"=="" GOTO :PARTMENU
    IF "!PARTITION!"=="1" SET PART=MBR& SET BOOT=bcdboot W:\Windows /s S: /f ALL& CLS
    IF "!PARTITION!"=="2" SET PART=GPT& SET BOOT=bcdboot W:\windows /s S: /f UEFI& CLS
    GOTO :!SVER!
    :1
    :: WinVista
    SET IMGFILE=\v
    ECHO.
    ECHO. Windows Vista (!ARCH!)
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Ultimate 
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" GOTO :1
    IF "!EDI!"=="1" SET IMGINDX=2& SET CHK= Windows Vista Home Basic& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=3& SET CHK= Windows Vista Home Premium& CLS & GOTO :CHK
    IF "!EDI!"=="3" SET IMGINDX=4& SET CHK= Windows Vista Ultimate& CLS & GOTO :CHK
    CLS & GOTO :1
    :2
    :: Win7
    SET IMGFILE=\7
    ECHO.
    ECHO. Windows 7 (!ARCH!)
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Professional
    ECHO. 4] Ultimate 
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" GOTO :2
    IF "!EDI!"=="1" SET IMGINDX=1& SET CHK= Windows 7 Home Basic& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=2& SET CHK= Windows 7 Home Premium&& CLS & GOTO :CHK
    IF "!EDI!"=="3" SET IMGINDX=3& SET CHK= Windows 7 Home Professional& CLS & GOTO :CHK
    IF "!EDI!"=="4" SET IMGINDX=4& SET CHK= Windows 7 Ultimate& CLS & GOTO :CHK
    CLS & GOTO :2
    :3
    :: Win8/1
    ECHO.
    ECHO. 1] Windows 8
    ECHO.
    ECHO. 2] Windows 8.1
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" GOTO :3
    IF "!EDI!"=="1" SET IMGFILE=\8& SET CHK1=Windows 8& CLS & GOTO :4
    IF "!EDI!"=="2" SET IMGFILE=\81& SET CHK1=Windows 8.1& CLS & GOTO :4
    CLS & GOTO :3
    :4
    ECHO.
    ECHO. !CHK1! (!ARCH!)
    ECHO. 
    ECHO. 1] Core
    ECHO.
    ECHO. 2] Professional
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" CLS & GOTO :3
    IF "!EDI!"=="1" SET IMGINDX=2 & SET CHK= Core& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=1 & SET CHK= Professional& CLS & GOTO :CHK
    CLS & GOTO :4
    :CHK
    :: Install OS Check
    TITLE Install Check
    ECHO.
    ECHO.Start installation of: !CHK1!!CHK! (!ARCH!) [!PART!]
    ECHO.
    SET /P CONT=[Y]es / [N]o: 
    IF "CONT"=="" CLS & GOTO :CHK
    IF /I "CONT"=="Y" CLS & GOTO :APPLYSETTINGS
    IF /I "CONT"=="N" SET PARTITION=& SET PART=& SET ARCHSEL=& SET EDI=& SET ARCH=& SET IMGFILE=& SET IMGINDX=& SET VER=& CLS & GOTO :MAIN
    
    :APPLYSETTINGS
    ECHO. 
    :: Applies image file and creates the partitions tables and boot settings. 
    DISKPART /S !BIN!!PART!.txt
    ECHO.DISKPART COMPLETE & pause
    DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
    ECHO.DISM COMPLETE & pause
    ping -n 2 localhost
    
    bcdboot W:\Windows /l EN-US
    ECHO.BCDBOOT COMPLETE & pause
    !BOOT!
    :LOG
    :: Outputs log of completed install. 
    ECHO.Installed !CHK1!!CHK! !ARCH! on !NowD! @ !NowT!
    Start CMD & EXIT
    
    
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    459
    169
    10
    hxxp://technet.microsoft.com/en-us/library/hh825686.aspx

    hxxp://technet.microsoft.com/en-us/library/hh825089.aspx

    I don't know if these will help :confused:
     
  16. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #16 Humphrey, Dec 18, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks for the links. I will check them out.

    Flipp3r, you mentioned that if

    Code:
    rem == 1. Windows RE tools partition ===============
    create partition primary size=300
    format quick fs=ntfs label="Windows RE tools"
    assign letter="T"
    set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
    gpt attributes=0x8000000000000001
    is added with diskpart that windows automatically adds WinRE.wim is added to the appropriate partition.

    I was reading this: http://technet.microsoft.com/en-us/library/hh825089.aspx

    Code:
    rem === Copy the Windows RE Tools to the Windows RE Tools partition ==========
    md T:\Recovery\WindowsRE
    copy W:\windows\system32\recovery\winre.wim T:\Recovery\WindowsRE\winre.wim
    
    So is this needed or not?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #17 Humphrey, Dec 18, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Having an issue with getting WinPE to love this script..

    Code as I have it now:
    StartNet.cmd
    Code:
    :: StartNet.CMD 
    :: Placed in System32 of WinPE
    @ECHO OFF
    :: Setup for InstallOS.cmd
    wpeutil UpdateBootInfo
    for /f "tokens=2* delims=     " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET DetectFirm=%%B
    :: Note: delims is a TAB followed by a space.
    if %DetectFirm%==0x1 SET FIRMWARE=BIOS
    if %DetectFirm%==0x2 SET FIRMWARE=UEFI
    :: Add script to detect files needed.
    for %%p 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 %%p:\logs SET LOGDIR=%%p:\Logs 2>nul
    for %%a 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 %%a:\installos.cmd %LOGDIR% %firmware% 2>nul
    :EXIT
    
    InstallOS.cmd
    Code:
    :: InstallOS.CMD v1.3
    :: Written by: Humphrey
    ::
    :: Runs from Windows PE to create partitions, apply a Windows image file, and setup the boot record.
    :: In this version, BIN and IMAGES need to be in the same folder as InstallOS.CMD
    ::
    @ECHO OFF
    :: SETUP
    SetLocal EnableDelayedExpansion
    CD /D %~dp0
    FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET NowT=%%A & FOR /F "TOKENS=*" %%A IN ('DATE/T') DO SET NowD=%%A
    SET BIN=.\bin\& SET IMGDIR=!BIN!Images\
    :MAIN
    TITLE Humphreys OS Installer
    :: Main Menu / OS Selection
    ECHO.
    ECHO. Select which Windows version to install.
    ECHO.
    ECHO. 1] Windows Vista
    ECHO. 2] Windows 7
    ECHO. 3] Windows 8
    ECHO.
    SET /P VER=What version to install?: 
    IF "!VER!"=="" CLS & GOTO :MAIN
    SET SVER=!VER! & CLS
    :ARCHSEL
    :: Architecture Menu
    ECHO.
    ECHO. 1] x32 (x86)
    ECHO.
    ECHO. 2] x64
    ECHO.
    SET /P ARCHSEL=What architecture to install?: 
    IF "!ARCHSEL!"=="" CLS & GOTO :ARCHSEL 
    IF "!ARCHSEL!"=="1" (SET Arch=x86& CLS) else SET Arch=x64& CLS
    :PARTMENU
    :: Partitioning Menu
    ECHO.
    ECHO.!FIRMWARE! was detected on boot.
    ECHO.
    ECHO. 1] MBR BIOS
    ECHO.
    ECHO. 2] GPT uEFI
    ECHO.
    SET /P PARTITION=What parition scheme to use?: 
    IF "!PARTITION!"=="" CLS & GOTO :PARTMENU
    IF "!PARTITION!"=="1" SET PART=MBR& SET BOOT=bcdboot W:\Windows /s S: /f ALL& CLS
    IF "!PARTITION!"=="2" SET PART=GPT& SET BOOT=bcdboot W:\windows /s S: /f UEFI& CLS
    GOTO :!SVER!
    :1
    :: WinVista
    SET IMGFILE=\v
    ECHO.
    ECHO. Windows Vista (!ARCH!)
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Ultimate 
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" CLS & GOTO :1
    IF "!EDI!"=="1" SET IMGINDX=2& SET CHK= Windows Vista Home Basic& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=3& SET CHK= Windows Vista Home Premium& CLS & GOTO :CHK
    IF "!EDI!"=="3" SET IMGINDX=4& SET CHK= Windows Vista Ultimate& CLS & GOTO :CHK
    CLS & GOTO :1
    :2
    :: Win7
    SET IMGFILE=\7
    ECHO.
    ECHO. Windows 7 (!ARCH!)
    ECHO.
    ECHO. 1] Home Basic
    ECHO. 2] Home Premium
    ECHO. 3] Professional
    ECHO. 4] Ultimate 
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" CLS & GOTO :2
    IF "!EDI!"=="1" SET IMGINDX=1& SET CHK= Windows 7 Home Basic& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=2& SET CHK= Windows 7 Home Premium&& CLS & GOTO :CHK
    IF "!EDI!"=="3" SET IMGINDX=3& SET CHK= Windows 7 Home Professional& CLS & GOTO :CHK
    IF "!EDI!"=="4" SET IMGINDX=4& SET CHK= Windows 7 Ultimate& CLS & GOTO :CHK
    :3
    :: Win8.x
    SET EDI=
    ECHO.
    ECHO. 1] Windows 8
    ECHO.
    ECHO. 2] Windows 8.1
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" CLS & GOTO :3
    IF "!EDI!"=="1" SET IMGFILE=\8& SET CHK1=Windows 8& CLS & GOTO :4
    IF "!EDI!"=="2" SET IMGFILE=\81& SET CHK1=Windows 8.1& CLS & GOTO :4
    :4
    :: Win8 Edition
    SET EDI=
    ECHO.
    ECHO. !CHK1! (!ARCH!)
    ECHO. 
    ECHO. 1] Core
    ECHO.
    ECHO. 2] Professional
    ECHO.
    SET /P EDI=What edition to install?: 
    IF "!EDI!"=="" CLS & GOTO :4
    IF "!EDI!"=="1" SET IMGINDX=2 & SET CHK= Core& CLS & GOTO :CHK
    IF "!EDI!"=="2" SET IMGINDX=1 & SET CHK= Professional& CLS & GOTO :CHK
    :CHK
    SET CONT=
    :: Install OS Check
    TITLE Install Check
    ECHO.
    ECHO.Start installation of: !CHK1!!CHK! (!ARCH!) [!PART!]
    ECHO.
    SET /P CONT=[Y]es / [N]o: 
    IF "!CONT!"=="" CLS & GOTO :CHK
    IF /I "!CONT!"=="Y" CLS & GOTO :APPLYSETTINGS
    IF /I "!CONT!"=="N" SET PARTITION=& SET PART=& SET ARCHSEL=& SET EDI=& SET ARCH=& SET IMGFILE=& SET IMGINDX=& SET VER=& CLS & GOTO :MAIN
    CLS & GOTO :CHK
    :APPLYSETTINGS
    ECHO. 
    :: Applies image file and creates the partitions tables and boot settings. 
    DISKPART /S !BIN!!PART!.txt
    DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
    bcdboot W:\Windows /l EN-US
    !BOOT!
    :LOG
    :: Outputs log of completed install. 
    ECHO.Installed !CHK1!!CHK! !ARCH! on !NowD! @ !NowT! >>!LOGDIR!\Final.log
    Start CMD
    notepad !LOGDIR!\Final.log
    

    I don't know why but startnet (i think) gives a "command completed successfully" output after it calls installOS which started after I added the line about setting the logdir variable.

    In InstallOS, I have set %BOOT% to either setup either a MBR/UEFI or just UEFI boot
    Code:
    IF "!PARTITION!"=="1" SET PART=MBR& SET BOOT=bcdboot W:\Windows /s S: /f ALL& CLS
    IF "!PARTITION!"=="2" SET PART=GPT& SET BOOT=bcdboot W:\windows /s S: /f UEFI& CLS
    It errors on this line when running the script but works if i type it manually. Manually as in either the %BOOT% to call that variables commands or the "bcdboot W:\Windows /s S: /f ALL"

    Will continue to test.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,493
    633
    60
    #18 Flipp3r, Dec 18, 2013
    Last edited by a moderator: Apr 20, 2017
    G'day Humprey,

    Just a few things I've observed.

    Once you've extracted the image, run bcdboot from the extracted location. This is why I boot 64bit WinPE or 32bit to match what I'm installing.
    (Done this from Vista days, could be different now).
    Code:
    W:\Windows\System32\bcdboot W:\Windows /l en-us /s S: /f BIOS
    W:\Windows\System32\bcdboot W:\Windows /l en-us /s S: /f UEFI
    Your using VER as a variable in your script. This is an existing (DOS) command. Type it at your cmd prompt.

    What does the ! do to the variable? Is it needed?

    Is this correct? "SET PART=GPT& SET" should it not be "SET PART=GPT & SET"??

    If you want to set the System up with FULL Recovery then YES.

    Code:
    :: ----------------- Register Windows RE Boot Image ----------------------------------------------------------
    W:\Windows\System32\Reagentc /Setreimage /Path T:\Recovery\WindowsRE /Target W:\Windows
    
    :: ----------------- Register the Push-Button Reset Recovery Image -------------------------------------------
    W:\Windows\System32\Reagentc /Setosimage /Path R:\RecoveryImage /Target W:\Windows /Index 1
     
  19. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,458
    981
    60
    #19 Humphrey, Dec 18, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    What? You mean CD to W:\Windows\System32 and BCDBOOT from there?

    I know of VER and ill change it. Could cause problems but idk.

    Is it need? no. I could use % but I like how ! looks. It is made possible by SetLocal EnableDelayedExpansion

    Yes this is correct. There isn't a space so that PART isn't set to "GPT_" (underscore representing the space) and "GPT"
    If there was a space, it would be looking for "GPT .txt" and not "GPT.txt"

    Run this an example: (Change nothing)
    Code:
    @ECHO OFF
    SET a=First Test& Set b=Second Test & SET c=Third Test
    ECHO."%a%" & ECHO."%b%" & ECHO."%c%"
    PAUSE
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,493
    633
    60
    #20 Flipp3r, Dec 19, 2013
    Last edited by a moderator: Apr 20, 2017
    NO, you don't need to CD but YES, run the version you extracted from W:.
    If you are in X:, the command "W:\Windows\System32\bcdboot" will run, no need to CD...

    Fantastic! I didn't know that!

    Yep, that works. I see now. Adding the SetLocal command & changing to ! works too....