@ECHO OFF REM VHD_Mount is edited English version of chenall's VHD_MNT batch for Win7 32/64 bit. REM It adds 2 shell commands to Registry: "Attach/Detach VHD" and REM "Create Dif VHD". To attach or detach a VHD, doubleclick its file. REM To Create a Dif VHD, select this command from RMC. The child VHD will be REM created in parent's directory and assigned relative to the parent name. REM If default vhd file association (key value HKEY_CLASSES_ROOT.vhd) is set in Registry REM (for example to "Windows.VirtualPC.HD"), you need to replace in :install and :uninstall subs below REM "HKCR.vhd..." with "HKCRWindows.VirtualPC.HD..." in all commands REM Doubleclick the batch to install & uninstall IF "%~n1"=="" GOTO :install SET "diskpart=echo exit|%ComSpec% /k prompt %%dsc%%$_|diskpart" IF "%2"=="PARENT" GOTO :PARENT :attach TITLE Autodetect.... SET dsc=list$Svdisk %diskpart%|find /i "%~1" > nul && goto :detach TITLE Attach VHD %* SET dsc=select$Svdisk$Sfile="%~f1" $_attach$Svdisk$S%2$_ GOTO :diskpart :detach TITLE Detach VHD %* SET dsc=select$Svdisk$Sfile="%~f1"$_detach$Svdisk$_ GOTO :diskpart :PARENT SHIFT /2 FOR /l %%i in (1,1,99) do IF not EXIST "%~dpn1_Dif%%i.vhd" (set "file=%~n1_Dif%%i.vhd" & GOTO :create) EXIT /b :create TITLE Create Dif VHD from Parent %1 echo. echo. VHD_MNT will create a Differencing VHD Image File echo. from Parent: %1 rem echo.Enter below a new Dif VHD file name, for example: %file% rem echo. Note: don't enter full path. echo. rem SET /p file=Enter new Dif VHD name: SET dsc=create$Svdisk$Sfile="%~dp1%file%"$SPARENT="%~f1"$_ TITLE Created Dif VHD %file% :diskpart %diskpart% rem PAUSE EXIT /b :install reg query "HKCR.vhdshellAttach/Detach VHDcommand" /ve 1>nul 2>nul && GOTO :uninstall reg add "HKCR.vhdshellAttach/Detach VHDcommand" /d "vhd_mnt.cmd "%%1" /f >nul reg add "HKCR.vhdshellCreate Dif VHDcommand" /d "vhd_mnt.cmd "%%1" PARENT" /f >nul reg add "HKCR.vhdDefaultIcon" /t REG_EXPAND_SZ /d "%%SystemRoot%%system32shell32.dll,8" /f >nul COPY /y "%~f0" "%SystemRoot%system32vhd_mnt.cmd" >nul echo. echo. VHD_Mount has been installed. echo. echo. Now you can doubleclick a VHD file to Attach/Detach, echo. or Create a Differencing VHD from selected Parent VHD echo. echo. Based on VHD_MNT by chenall 2011-04-29 PAUSE EXIT :uninstall echo. reg delete "HKCR.vhdshell" /f >nul DEL /f "%SystemRoot%system32vhd_mnt.cmd" echo. echo. VHD_Mount has been uninstalled. echo. echo. Based on VHD_MNT by chenall 2011-04-29 PAUSE EXIT
The batch adds convenience compare to using Disk Management or Diskpart - it's handy basic shell VHD tool. Read REMarks in the code for more usage details. It will be improved to add more common ops with VHDs. For example, it doesn't auto assign a drive letter to an existing VHD volume when attached, if its default drive letter is used at the moment by another drive or was never assigned, or removed.
You're welcome to suggest improvement ideas, for example a fix to check if a newly attached VHD got a drive letter & get mounted (without checking its content that may be unknown), and if not, check available drive letters, and auto assign one of these to the VHD Volume? What would be the shortest way to do it?
Attached is the latest VHD_Mount version (it may differ from the code printed above).