DESCRIPTION:
VHD-To-BCD adds a virtual-hard-disk to Windows' BootManager using BCDEdit (which is part of Windows).
IMPORTANT:
The script will not change your default bootdevice or anything else. It just automates the things you need to do by hand to add a VHD to BootManager:
bcdedit /copy {default} /d "<bootdescription>"
bcdedit /set {GUID} device vhd=[<driveletter>:]\<path\filenname.vhd>
bcdedit /set {GUID} osdevice vhd=[<driveletter>:]\<path\filenname.vhd>
bcdedit /set {GUID} detecthal on
The "tricky" thing to automate these 4 lines is to get the default GUID and the brackets around the driveletter ("[C:]")! This is what the script does.
I tested it on several Windows 8.1 and 10 installations without problems. In the worst case (e.g. you run the command not using a .vhd-file) you'll get a new boot-entry, which simply doesn't work, but it will not affect your default bootdevice and you can easily remove the entry (see "Remove a VHD from BootManager").
If you're using Windows 7 or Bitlocker, please be careful, as I did not test it!
Nethertheless I need to say that you use following script on your own risk and that I'm not responsible for any damage to your OS.
INSTALLATION:
Copy the code at the bottom in your language to clipboard, create a new filetype for ".vhd" and ".vhdx" and add it to the contextmenu by creating a new entry. Set it to "MS-DOS-Batch-function".
When done easily rightclick a vhd(x)-file and choose "Add VHD to bootmanager" (or whatever you named it). Finished!
CHOOSE CORRECT LANGUAGE
As said we need the GUID, which we'll get after copying default boot-entry. It'll be copied to a tempfile and determined by using tokens ("word-counting"). But due to different output-text depending on the used language, the tokens-value in the script differs. Examples:
EN: "The entry was successfully copied to {GUID}.", so the GUID is the 7th word (tokens).
DE: "Der Eintrag wurde erfolgreich in {GUID} kopiert.", so the GUID is the 6th word (tokens).
That's why you need to choose the correct language (or change the tokens-value) to get the GUID.
If you should use the wrong language, you'll get only a non-working boot-entry, but it will not affect or destroy your bootdevices. If that should happen, just remove the entry (see "Delete a VHD from Bootmanager).
If somebody can help me getting the GUID out of a text without using tokens (e.g. find and copy everything between "{...}"), we wouldn't need different scripts for each language and it would run on all languages!
BOOT FROM A VIRTUAL-HARD-DISK:
Go to startmenu, hold "shift"-key and press "restart". Once in Bootmanager go to "Use another operating system" and choose the VHD.
If you want to enter the Bootmanager from DirOpus, just add following code to a button:
@runmode:hide
%windir%\system32\shutdown.exe /r /o /t 0
BACKUP BCD:
Creating a backup of the current BCD (run command prompt with admin rights):
bcdedit /export C:\BCD_Backup
REMOVE A VHD FROM BOOTMANAGER:
To remove a VHD from BootManager simply use msconfig or free EasyBCD and... delete it!
VHD-To-BCD
English Version:
[code]@admin
@runmode hide
@nofilenamequoting
@externalonly
set VHDPATH={filepath$}
set BOOTENTRY="{dlgstringS|Add virtual harddisk to bootmanager.\n\nPlease enter description or press cancel to abort:|Virtual-Hard-Disk}"
cmd /c " bcdedit /copy {default} /d %BOOTENTRY% " > %Temp%\VHD-To-BCD_GUID.txt
Rem ---------------------------------------------------
Rem ENTER YOUR TOKENS-VALUE HERE (English=7; German=6):
Rem ---------------------------------------------------
for /F "tokens=7 delims=. " %%A in (%Temp%\VHD-To-BCD_GUID.txt) DO set GUID=%%A
set STRIPPEDDRIVE=%VHDPATH:~1,2%
set STRIPPEDPATH=%VHDPATH:~3%
del %Temp%\VHD-To-BCD_GUID.txt
bcdedit /set %GUID% device vhd="[%STRIPPEDDRIVE%]%STRIPPEDPATH%"
bcdedit /set %GUID% osdevice vhd="[%STRIPPEDDRIVE%]%STRIPPEDPATH%"
bcdedit /set %GUID% detecthal on
[/code]
German Version:
[code]@admin
@runmode hide
@nofilenamequoting
@externalonly
set VHDPATH={filepath$}
set BOOTENTRY="{dlgstringS|Die virtuelle Harddisk wird dem Bootmanager hinzugefügt.\n\nBitte gewünschten Bootmenü-Eintrag eingeben:|Virtual-Hard-Disk}"
cmd /c " bcdedit /copy {default} /d %BOOTENTRY% " > %Temp%\VHD-To-BCD_GUID.txt
Rem ---------------------------------------------------
Rem ENTER YOUR TOKENS-VALUE HERE (English=7; German=6):
Rem ---------------------------------------------------
for /F "tokens=6 delims=. " %%A in (%Temp%\VHD-To-BCD_GUID.txt) DO set GUID=%%A
set STRIPPEDDRIVE=%VHDPATH:~1,2%
set STRIPPEDPATH=%VHDPATH:~3%
del %Temp%\VHD-To-BCD_GUID.txt
bcdedit /set %GUID% device vhd="[%STRIPPEDDRIVE%]%STRIPPEDPATH%"
bcdedit /set %GUID% osdevice vhd="[%STRIPPEDDRIVE%]%STRIPPEDPATH%"
bcdedit /set %GUID% detecthal on
[/code]