yet another stupid script - that will help you to install additional Image on your free space, using current live OS instead using external MS Setup / some other s**t after reboot, you will have a new boot menu new installation will begin make sure to put wimlib-imagex in the windows directory or in same path, where tool located Latest version (17/03/2023) ~ fix problem with names containing ' Or ", fail at start ~ fix the problem with a short path. will detect full path of the file `How to ?` Code: Install ISO Name [en_windows_11_consumer_editions_version_22h2_x64_dvd] WIM Image Index [?] --- USER SELECTION --- Partition Size [?] --- AUTO DETE SIZE --- "USB PE Tool [LiveOS]" "d:\Setup\en_windows_11_consumer_editions_version_22h2_x64_dvd.iso" Install ISO Name [en_windows_11_consumer_editions_version_22h2_x64_dvd] WIM Image Index [?] --- USER SELECTION --- Partition Size [120] GB "USB PE Tool [LiveOS]" "d:\Setup\en_windows_11_consumer_editions_version_22h2_x64_dvd.iso" 120 Install ISO Name [en_windows_11_consumer_editions_version_22h2_x64_dvd] WIM Image Index [9] Partition Size [80] GB "USB PE Tool [LiveOS]" "d:\Setup\en_windows_11_consumer_editions_version_22h2_x64_dvd.iso" 9 80 USB PE Tool [LiveOS] Spoiler: Source Code Code: <# : standard way of doing hybrid batch + powershell scripts @cls @echo off >nul chcp 437 SETLOCAL EnableDelayedExpansion title USB PE Tool set "args=" & set "args=%*" if defined args set "args=!args:"=!" if defined args set "args=!args:'=!" if defined args if /i "A!args!" NEQ "A" ( goto :Args_OK ) echo. echo How to use echo: echo Install ISO Name [en_windows_11_consumer_editions_version_22h2_x64_dvd] echo WIM Image Index [^?] --- USER SELECTION --- echo Partition Size [^?] --- AUTO DETE SIZE --- echo. echo "%~nx0" "d:\Setup\en_windows_11_consumer_editions_version_22h2_x64_dvd.iso" echo: echo Install ISO Name [en_windows_11_consumer_editions_version_22h2_x64_dvd] echo WIM Image Index [^?] --- USER SELECTION --- echo Partition Size [120] GB echo. echo "%~nx0" "d:\Setup\en_windows_11_consumer_editions_version_22h2_x64_dvd.iso" 120 echo: echo Install ISO Name [en_windows_11_consumer_editions_version_22h2_x64_dvd] echo WIM Image Index [9] echo Partition Size [80] GB echo. echo "%~nx0" "d:\Setup\en_windows_11_consumer_editions_version_22h2_x64_dvd.iso" 9 80 echo: exit /b :Args_OK set "fName=" cd /d "%~dp0" for /f "tokens=*" %%$ in ('"2>nul where "%~n0""') do ( set "fName=%%$" goto :skip ) echo fail to get file path location .. timeout 2 /nobreak exit /b :skip set "rand=%temp%\%random%.ps1" >nul 2>&1 copy /y "!fName!" "%rand%" powershell -nop -ep bypass -f "%rand%" %* >nul 2>&1 del /q "%rand%" exit /b #> <# Powershell Code Start #> # Powershell: loading a registry hive from file # https://blog.redit.name/posts/2015/powershell-loading-registry-hive-from-file.html Function Import-RegistryHive { [CmdletBinding()] Param( [String][Parameter(Mandatory=$true)]$File, # check the registry key name is not an invalid format [String][Parameter(Mandatory=$true)][ValidatePattern('^(HKLM\\|HKCU\\)[a-zA-Z0-9- _\\]+$')]$Key, # check the PSDrive name does not include invalid characters [String][Parameter(Mandatory=$true)][ValidatePattern('^[^;~/\\\.\:]+$')]$Name ) # check whether the drive name is available $TestDrive = Get-PSDrive -Name $Name -EA SilentlyContinue if ($TestDrive -ne $null) { throw [Management.Automation.SessionStateException] "A drive with the name '$Name' already exists." } $Process = Start-Process -FilePath "$env:WINDIR\system32\reg.exe" -ArgumentList "load $Key $File" -WindowStyle Hidden -PassThru -Wait if ($Process.ExitCode) { throw [Management.Automation.PSInvalidOperationException] "The registry hive '$File' failed to load. Verify the source path or target registry key." } try { # validate patten on $Name in the Params and the drive name check at the start make it very unlikely New-PSDrive will fail New-PSDrive -Name $Name -PSProvider Registry -Root $Key -Scope Global -EA Stop | Out-Null } catch { throw [Management.Automation.PSInvalidOperationException] "A critical error creating drive '$Name' has caused the registy key '$Key' to be left loaded, this must be unloaded manually." } } Function Remove-RegistryHive { [CmdletBinding()] Param( [String][Parameter(Mandatory=$true)][ValidatePattern('^[^;~/\\\.\:]+$')]$Name ) # set -ErrorAction Stop as we never want to proceed if the drive doesnt exist $Drive = Get-PSDrive -Name $Name -EA Stop # $Drive.Root is the path to the registry key, save this before the drive is removed $Key = $Drive.Root [GC]::Collect() [GC]::WaitForPendingFinalizers() # remove the drive, the only reason this should fail is if the reasource is busy Remove-PSDrive $Name -EA Stop $Process = Start-Process -FilePath "$env:WINDIR\system32\reg.exe" -ArgumentList "unload $Key" -WindowStyle Hidden -PassThru -Wait if ($Process.ExitCode) { # if "reg unload" fails due to the resource being busy, the drive gets added back to keep the original state New-PSDrive -Name $Name -PSProvider Registry -Root $Key -Scope Global -EA Stop | Out-Null throw [Management.Automation.PSInvalidOperationException] "The registry key '$Key' could not be unloaded, the key may still be in use." } } Function Live-OS-Install { Param ( [parameter(Mandatory=$true)] [STRING] $Wim, [INT] $Index, [INT] $Size ) Begin { #nothing here } Process { $wimlib = Get-Command -name "Wimlib-imagex.exe" -ErrorAction SilentlyContinue if (!$wimlib -or (!(Test-Path($wimlib[0].Source)))) { Write-Host "error ### Wimlib-imagex.exe couldn't found ...." Write-Host return } if (!$wim.EndsWith('.iso') -And !$wim.EndsWith('.wim') -And !$wim.EndsWith('.esd') -And !$wim.EndsWith('.swm')) { Write-Host "error ### Bad file ???? ......." Write-Host return } $ISO = $null if ($wim.EndsWith('.iso')) { $item = Get-ChildItem $wim -ErrorAction SilentlyContinue if ($item -and $item.Exists) { $ISO = $item.FullName } if (!$ISO) { Write-Host "error ### Bad file ???? ......." Write-Host return } Dismount-DiskImage -ImagePath $ISO -ErrorAction SilentlyContinue | Out-Null Mount-DiskImage -ImagePath $ISO -ErrorAction SilentlyContinue | Out-Null $image = Get-DiskImage $ISO if ($image) { $DriveLetter = (Get-DiskImage $ISO | Get-Volume).DriveLetter } if (!$DriveLetter){ Write-Host "error ### Bad ISO file ......." Write-Host return } $wim = $null if (Test-Path("$($DriveLetter):\Sources\install.wim")) { $wim = "$($DriveLetter):\Sources\install.wim" } if (Test-Path("$($DriveLetter):\Sources\install.swm")) { $wim = "$($DriveLetter):\Sources\install.swm" } if (Test-Path("$($DriveLetter):\Sources\install.esd")) { $wim = "$($DriveLetter):\Sources\install.esd" } } if (!($wim.EndsWith('.iso'))) { $item = $null $item = Get-ChildItem $wim -ErrorAction SilentlyContinue $wim = $null if ($item -and $item.Exists) { $wim = $item.FullName } } if ((!$wim) -or (!(Test-Path($wim)))) { Write-Host "error ### File not exist ......." Write-Host return } $nl = [System.Environment]::NewLine $array = cmd /c ""$wimlib[0].Source"" info $wim | Select-String "^Description:" if (!$array -or ($array.length -eq 0)) { Write-Host "error ### index not found ......." Write-Host return } Write-Host for ($i=0; $i -lt $array.length; $i++) { $edition = $array[$i].ToString().Split(':').Replace(' ','')[1] if (@($i+1) -lt 10) { Write-Host "Index $($i+1) :: $($edition)" } if (@($i+1) -ge 10) { Write-Host "Index $($i+1) :: $($edition)" } } write-host if ($array.length -eq 1) { $Index = [INT](1) } if ($array.length -gt 1) { do { try { $oKey = $null if (!$Index) { $selected = Read-Host -Prompt 'Select ID: ' $id = $selected -as [INT] } if ($Index) { $oKey = $Index $Index = $null } 1.. $array.length | % { if ($oKey -and ($_ -eq $oKey)) { $Index = $_ } if (!$oKey -and ($_ -eq $id)) { $Index = $_ } } } catch { } } While (!$Index) } if (!$Size) { $part = get-partition | ? DriveLetter -eq 'c' if ($part) { $disk = get-disk $part.DiskNumber } if ($disk) { $Size = [int]($disk.Size/1GB) $disk | get-partition | % { $Size = ($Size - ($_.size/1GB)) } } $Size = ($Size-1) } if (!$Size) { Write-Host "error ### disk size configuration can't be found ...." " Make sure you have enougth space etc ......" Write-Host return } $DISKSIZE = ($Size * 1024 * 1024 * 1024) if ($Size -le 30) { Write-Host "error ### minimum size is 30 GB ...." Write-Host return } Write-Host "Index is $($Index)" "size is $($DISKSIZE)" "wim file is $($wim)" Write-Host Get-Service -Name "ShellHWDetection" | Stop-Service -force -ErrorAction SilentlyContinue New-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers" -Name DisableAutoplay -PropertyType dword -Value 0x1 -Force -ErrorAction SilentlyContinue | Out-Null $partition = get-partition | ? DriveLetter -eq 'c' if ($partition) { "# Create Volume" $ltr = New-Partition -DiskNumber $partition.DiskNumber -Size $DISKSIZE -GptType "{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}" -AssignDriveLetter } if ($ltr.DriveLetter) { "# Format Volume" $ProgressPreference = 'SilentlyContinue' # Subsequent calls do not display UI. Format-Volume -DriveLetter $ltr.DriveLetter -FileSystem NTFS -Confirm -ErrorAction Continue | Out-Null $ProgressPreference = 'Continue' # Subsequent calls do not display UI. } if (!(Test-Path("$($ltr.DriveLetter):\"))) { Write-Host "error ### Format drive failed ......." Write-Host return } "# Apply Image to Volume" (cmd /c ""$wimlib[0].Source"" apply $wim $Index "$($ltr.DriveLetter):") *> $null "# Update BCD Store" (cmd /c bcdboot "$($ltr.DriveLetter):\windows" /l en-us /addlast) *> $null Get-Service -Name "ShellHWDetection" | Start-Service -ErrorAction SilentlyContinue New-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers" -Name DisableAutoplay -PropertyType dword -Value 0x0 -Force -ErrorAction SilentlyContinue | Out-Null New-Item -Path "$($ltr.DriveLetter):\windows" -Name "Panther" -ItemType Directory -ErrorAction SilentlyContinue | Out-Null Import-RegistryHive -File "$($ltr.DriveLetter):\windows\system32\config\SYSTEM" -Key "HKLM\TEMP_SYSTEM" -Name "SystemHive" -ErrorAction SilentlyContinue | Out-Null New-ItemProperty -Path "SystemHive:\Setup" -Name UnattendFile -PropertyType string -Value 'c:\windows\Panther\AutoUnattend.xml' -Force -ErrorAction SilentlyContinue | Out-Null Remove-RegistryHive -Name SystemHive | Out-Null Write-Host "$ ------------------------------------------- $" "$ Untended file location set to: $" "$ $($ltr.DriveLetter):\windows\Panther\AutoUnattend.xml $" "$ ------------------------------------------- $" # Force Dismount Image if ($ISO -and (Test-path($ISO)) -and ($ISO.EndsWith('.iso',"CurrentCultureIgnoreCase"))) { Dismount-DiskImage -ImagePath $ISO -ErrorAction SilentlyContinue | Out-Null } Write-Host "Done ..." timeout 4 return } } if ($args[0] -and !$args[1]) { # Case Wim file only # user choice wim index later # disk size will detect automaticly try { $wim = $args[0].ToString() Live-OS-Install -Wim $wim } catch { write-host "error ### error occurred" } } if ($args[0] -and $args[1]) { if ($args[2]) { try { $wim = $args[0].ToString() $Index = [int]($args[1]) $Size = [int]($args[2]) Live-OS-Install -Wim $wim -index $Index -size $Size } catch { write-host "error ### error occurred" } } # Case Wim file + size only # user choice wim index later if (!$args[2]) { try { $wim = $args[0].ToString() $Size = [int]($args[1]) Live-OS-Install -Wim $wim -size $Size } catch { write-host "error ### error occurred" } } } # Force Dismount Image $ISO = $args[0].ToString() if ($ISO -and (Test-path($ISO)) -and ($ISO.EndsWith('.iso',"CurrentCultureIgnoreCase"))) { Dismount-DiskImage -ImagePath $ISO -ErrorAction SilentlyContinue | Out-Null } # Restore Progress bar $ProgressPreference = 'Continue' # Subsequent calls do not display UI. # Restore AutoPlay Service & Handler Get-Service -Name "ShellHWDetection" | Start-Service -ErrorAction SilentlyContinue New-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers" -Name DisableAutoplay -PropertyType dword -Value 0x0 -Force -ErrorAction SilentlyContinue | Out-Null <# Powershell Code End #>
"so you end up with another system, on the current disk" Does "current disk" mean "logical partition" or "physical hard disk but different partition" ?
In gpt .. there is no such thing Another data partition on the same disk With a new os installed on her it
did some massive re-code ... and update the version to [v2.0] need to update this and replace them with PS equ commands later Code: (cmd /c md "$($ltr.DriveLetter):\windows\Panther") *> $null (cmd /c sc start ShellHWDetection) *> $null (cmd /c reg load HKLM\_SYSTEM "$($ltr.DriveLetter):\windows\system32\config\SYSTEM") *> $null (cmd /c reg add "HKLM\_SYSTEM\Setup" /f /v UnattendFile /t reg_SZ /d "c:\windows\Panther\AutoUnattend.xml") *> $null (cmd /c reg unload HKLM\_SYSTEM) *> $null (cmd /c reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers" /f /v DisableAutoplay /t reg_dword /d 0x0) *> $null
Update it again replace more CMD calls, with PS calls it work so fine, I was able to install new OS, in my work computer, using current Live OS and also able to use my Custom OEM pack without need any USB / external disk was using ISO from luz.. ftp Site very helpful …
back in time. [mbr] (if I'm not wrong, I'm pretty sure that's how it was) (boot was saved in the Primary partition with the windows directory) Code: diskpart -> create -> Primary diskpart -> create -> EXTENDED -> Logical nowadays. [gpt] all partitions are primary, 1'st is a boot, 2'st is Microsoft Reserved Partition, the rest is data type Code: create partition primary size=100 id=c12a7328-f81f-11d2-ba4b-00a0c93ec93b create partition primary size=16 id=e3c9e316-0b5c-4db8-817d-f92df00215ae Create Partition Primary id=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 From disk part info Code: EFI System partition: c12a7328-f81f-11d2-ba4b-00a0c93ec93b Microsoft Reserved partition: e3c9e316-0b5c-4db8-817d-f92df00215ae Basic data partition: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 LDM Metadata partition on a dynamic disk: 5808c8aa-7e8f-42e0-85d2-e1e90434cfb3 LDM Data partition on a dynamic disk: af9b60a0-1431-4f62-bc68-3311714a69ad Recovery partition: de94bba4-06d1-4d40-a16a-bfd50179d6ac UEFI/GPT-based hard drive partitions https://learn.microsoft.com/en-us/w...itions?source=recommendations&view=windows-11
The old MBR (Master Boot Record) partition scheme has Primary and Extended partitions. Extended partitions are actually containers for logical drives. The whole shebang was necessary because MBR would not support more than four Primary partitions per disk. The new GPT (GUID Partiton Table) can support up to 127 Primary partitions IIRC, and has thus done away with the Extended ones.
GUID Partition Table or in Clear we can Say Disk Layout Now what does this GUID stands for . kindly abbreviate it ?
wimboot is in theory a brilliant idea, practically is stupid because wims are not upgradeable, so any cumulative update make the storage to grow larger and larger. Even MS realized that, after they started full steam with wimboot in win81 days. Native vhds are the way to go, to say better lzx compressed native vhdx are the way to go. No matter if you use them as a one time boootable usb thumbdrives or as a main OS, or as a main OS, or as a one of many multiple boot OSes. The list of advantage over the stone age multiple partitions scheme are endless, but on MDL seem that no one gets that obvious thing. ( Except @berr1sfueller ) https://forums.mydigitallife.net/threads/shazzam-a-native-windows-image-deployment-tool.86132/
I can use my other USB pe tool .. To create new machine on vhd Only Missing part is .. create vhd. Attach it. Than do the doing ... Than update bcd store with new vhd .. This can be an idea ( It's not wim boot. Btw. It create another partition With new win image Like win setup just from live os )
His tool .. create vhd after 1 hour of trying Told him .. he don't care .. I need something more simple than this .. Maybe another cmd just to create and attach vhd And update boot with new vhd ... And using my second tool Create partition with image on new vhd It's good idea .. Edit. This can be good alternative
This is practically monkey proof (IMO one of the best tool around) to install on vhd, real partitions, add drivers, set sane default options, create vhds and manage the bootloader entries with a couple of mouse clicks https://msfn.org/board/topic/149612-winntsetup-v53/ With the added bonus that you don't need any script/hack to deploy the ugly eleven thing. Not that doing everything manually is complicate
even Rufus can do a better job than this, it req. that you create the partitions maybe something like this ... just with args and then Rufus [or my lovely USB BE TOOL Unsafe ver.] you choose the image, and then everything is automatic
what you mention ... winntsetup which req. from the user to create a partitions ~~~~~~~~~~~~ it's much easier to use -> Simple VHD Manager v1.4 (have a built-in option to create vhd & boot from selected VHD) and then use Rufus tool to create an image on selected VHD ~~~~~~~~~~~~ After little more tests, and some fixes, it works fine, create File + boot menu I maybe make it a user choice later it has the potential Code: rem CMD file to add a VHD(x) boot object in BCD by MaloK rem https://www.tenforums.com/virtualization/193557-cmd-file-add-vhd-x-boot-object-bcd.html @cls @echo off set "DriveLetter=D" set "FullPath=TestX.vhdx" set "Maxvhdsize=60000" set "type=expandable" set "Name=W11 Test Version" >part.txt echo create vdisk file="%DriveLetter%:\%FullPath%" maximum=%Maxvhdsize% type=%type% >>part.txt echo select vdisk file="%DriveLetter%:\%FullPath%" >>part.txt echo attach vdisk diskpart /s part.txt del /q part.txt for /f "tokens=2 delims={}" %%g in ('bcdedit.exe /create /d "%Name%" /Device') do (set device_id={%%g}) bcdedit /set %device_id% device vhd=[%DriveLetter%:]"\%FullPath%" for /f "tokens=2 delims={}" %%g in ('bcdedit.exe /create /d "%Name%" /application osloader') do (set guid={%%g}) bcdedit /set %guid% device vhd=[%DriveLetter%:]"\%FullPath%",%device_id% bcdedit /set %guid% osdevice vhd=[%DriveLetter%:]"\%FullPath%",%device_id% bcdedit /set %guid% systemroot \windows bcdedit /set %guid% path \Windows\system32\winload.efi bcdedit /set %guid% winpe no bcdedit /set %guid% detecthal yes bcdedit /set %guid% locale en-US bcdedit /displayorder %guid% /addlast bcdedit /set {bootmgr} displaybootmenu True bcdedit /set {bootmgr} timeout 5
It's a good rule to understand / know what one talks about. Clearly you never used this program or didn't understand how it works. There's a nice vhd button, that does in two click everything you need (hint: bottom right), if you need it (aka you didn't provide a vhd by yourself. Obviously it works also on old school partitions. In my country we have a joke about the "office for complication of simple affairs", I'm sure they are hiring, send your CV Seriously, you can't compare a dirty script written in minutes, with a GUI program, with years of evolution and feedback.
ok ........... I accept it ........... "VHD Tool [RP].cmd" "W11 Test Version" "D" "W.11.Test.v1" 60 Spoiler: Image "usb pe tool [se]" Spoiler: Image "usb pe tool [se]" 3 d:\Setup\en_windows_11_consumer_editions_version_22h2_x64_dvd.iso -PE Spoiler: Image BootIce Spoiler: Image Pe-Tool OEM helper (will copy each folder to each own place) Spoiler: Image It Worked, no GUI is involved Spoiler: Some sort of images https://imgur.com/hcKb0dy https://imgur.com/GKdhAwN VHD Script Spoiler: Script Code: rem CMD file to add a VHD(x) boot object in BCD by MaloK rem https://www.tenforums.com/virtualization/193557-cmd-file-add-vhd-x-boot-object-bcd.html @cls @echo off >nul chcp 437 title VHD Helper Tool SETLOCAL EnableDelayedExpansion set "type=expandable" set "part=%windir%\temp\part.txt" rem Run as administrator, AveYo: ps\VBS version >nul fltmc || ( set "_=call "%~dpfx0" %*" powershell -nop -c start cmd -args '/d/x/r',$env:_ -verb runas || ( mshta vbscript:execute^("createobject(""shell.application"").shellexecute(""cmd"",""/d/x/r "" &createobject(""WScript.Shell"").Environment(""PROCESS"")(""_""),,""runas"",1)(window.close)"^))|| ( cls & echo:& echo Script elavation failed& pause) exit ) set "args=" & set "args=%*" if defined args set "args=!args:"=!" if defined args set "args=!args:'=!" if defined args if /i "A!args!" NEQ "A" ( goto :Args_OK ) echo. echo How to use echo: echo Drive [D] echo Full Name [W.11] echo VHD Size [60] - 60GB echo Boot Name [W11 Test Version] echo. echo "%~nx0" "W11 Test Version" D "W.11" 60 echo: exit /b :Args_OK cls echo: for %%$ in (Name, DriveLetter, FullPath, Maxvhdsize) do ( set "%%$=") set "Name=%~1" set "DriveLetter=%~2" set "FullPath=%~3" set "Maxvhdsize=%~4" if not defined Name (set "err=Bad Args" & goto :error) if not defined DriveLetter (set "err=Bad Args" & goto :error) if not defined FullPath (set "err=Bad Args" & goto :error) if not defined Maxvhdsize (set "err=Bad Args" & goto :error) for %%$ 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 /i "!DriveLetter!" == "%%$" ( if exist %%$:\ ( goto :drive_found ) ) ) (set "err=Bad Drive Letter" & goto :error) :drive_found if /i "!FullPath:~-4!" NEQ ".vhd" if /i "!FullPath:~-5!" NEQ ".vhdx" ( set "FullPath=!FullPath!.vhdx" ) if exist "%DriveLetter%:\%FullPath%" ( echo "%DriveLetter%:\%FullPath%" --- already exist echo: goto :Drive_exist ) (>nul 2>nul 3>nul echo. > "%DriveLetter%:\%FullPath%") && (>nul 2>nul del /q "%DriveLetter%:\%FullPath%" ) || ( set "err=Bad file path" goto :error ) set "d_Size=" set /a d_Size=(!Maxvhdsize!+1) if not defined d_Size ( set "err=Bad Drive Size" goto :error ) REM if defined d_Size if !Maxvhdsize! == !d_Size! ( REM set "err=Bad Drive Size" REM goto :error REM ) echo "!Maxvhdsize!" | >nul 2>nul findstr /r [aA-zZ] && ( set "err=Bad Drive Size" goto :error ) set /a Maxvhdsize=(!Maxvhdsize!*1024) >%part% echo create vdisk file="%DriveLetter%:\%FullPath%" maximum=%Maxvhdsize% type=%type% >>%part% echo select vdisk file="%DriveLetter%:\%FullPath%" >>%part% echo attach vdisk 2>nul diskpart /s %part% >nul 2>&1 del /q %part% echo: :Drive_exist set "device_id=" for /f "tokens=2 delims={}" %%g in ('"2>nul bcdedit.exe /create /d "%Name%" /Device"') do (set device_id={%%g}) if not defined device_id (set "err=Cant find device ID" & goto :error) set "guid=" bcdedit /set %device_id% device vhd=[%DriveLetter%:]"\%FullPath%" for /f "tokens=2 delims={}" %%g in ('"2>nul bcdedit.exe /create /d "%Name%" /application osloader"') do (set guid={%%g}) if not defined guid (set "err=Cant find GUID" & goto :error) bcdedit /set %guid% device vhd=[%DriveLetter%:]"\%FullPath%",%device_id% bcdedit /set %guid% osdevice vhd=[%DriveLetter%:]"\%FullPath%",%device_id% bcdedit /set %guid% systemroot \windows bcdedit /set %guid% path \Windows\system32\winload.efi bcdedit /set %guid% winpe no bcdedit /set %guid% detecthal yes bcdedit /set %guid% locale en-US bcdedit /displayorder %guid% /addlast bcdedit /set {bootmgr} displaybootmenu True bcdedit /set {bootmgr} timeout 5 timeout 2 /nobreak exit /b :error echo: echo ERR :: %ERR% echo: exit /b Helper Tool to clean BCD STORE + index 4 Spoiler: Some s**ti code Code: <# : standard way of doing hybrid batch + powershell scripts @cls @echo off >nul chcp 437 title Additional Partitioning Helper :::: Run as administrator, AveYo: ps\vbs version 1>nul 2>nul fltmc || ( set "_=call "%~f0" %*" & powershell -nop -c start cmd -args'/d/x/r',$env:_ -verb runas || ( >"%temp%\Elevate.vbs" echo CreateObject^("Shell.Application"^).ShellExecute "%~dpf0", "%*" , "", "runas", 1 >nul "%temp%\Elevate.vbs" & del /q "%temp%\Elevate.vbs" ) exit) @powershell -noexit -noprofile "iex((Get-Content('%~dfnx0') -Raw))"&exit #> <# Powershell Code Start #> class Boot_info { [string]$identifier [string]$device [string]$path [string]$description [string]$locale [string]$osdevice [string]$inherit [string]$recoverysequence [string]$displaymessageoverride [string]$recoveryenabled [string]$isolatedcontext [string]$allowedinmemorysettings [string]$nx [string]$bootmenupolicy [string]$systemroot [string]$resumeobject } function Get_Boot_info { Param ( [STRING] $path ) if ($path -and (!(Test-Path($path)))) { return $null } $addin = $null if ($path) { $addin = "/store ""$($path)""" } $nl = [System.Environment]::NewLine $store = (cmd /c "bcdedit $($addin) /enum") | Out-String #combine into one string $List = $store -split "$nl$nl" #split the entries, only empty new lines $bl = $List -match 'Windows Boot Loader' $arr = [System.Collections.ArrayList]::new() $bl | % { $obj = $_ -Split $nl $bi = [Boot_info]::new() ForEach ($itm in $obj) { if ($itm -match 'Windows Boot Loader|-------------------') { continue } $data = [regex]::Replace($itm, "\s+", " ").Split(' ') switch ($data[0]) { "identifier" {$bi.identifier = $data[1]} "device" {$bi.device = $data[1]} "path" {$bi.path = $data[1]} "description" {$bi.description = $data[1],$data[2]} "locale" {$bi.locale = $data[1]} "osdevice" {$bi.osdevice = $data[1]} "inherit" {$bi.inherit = $data[1]} "recoverysequence" {$bi.recoverysequence = $data[1]} "displaymessageoverride" {$bi.displaymessageoverride = $data[1]} "recoveryenabled" {$bi.recoveryenabled = $data[1]} "isolatedcontext" {$bi.isolatedcontext = $data[1]} "allowedinmemorysettings" {$bi.allowedinmemorysettings = $data[1]} "nx" {$bi.nx = $data[1]} "bootmenupolicy" {$bi.bootmenupolicy = $data[1]} "systemroot" {$bi.systemroot = $data[1]} "resumeobject" {$bi.resumeobject = $data[1]} } } $arr.Add($bi) | out-null } return $arr } $info = Get-Partition | ? DriveLetter -eq 'c' if ($info -and ($info.PartitionNumber -eq 3)) { write-host write-host 'Remove additional partition' Remove-Partition -DiskNumber $info.DiskNumber -PartitionNumber 4 -Confirm:$false -ea 0 write-host 'Re-Build Origional Store' bcdboot /bcdclean | out-null Get_Boot_info | % { bcdedit /delete "$($_.identifier)" | out-null } bcdboot $env:windir /l en-us | out-null } write-host pause exit <# Powershell Code End #>