Done MOUNTISO: Add support for VHD / VHDX files

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,923
51
Albuquerque, NM
prospero.unm.edu
Also I'd suggest: (1) a /RW option to mount VHDs in read/write mode (ignore for .ISOs), and (2) allow more than one mount point to be specified (again, useful only for VHD files.)
 

samintz

Scott Mintz
May 20, 2008
1,355
12
Solon, OH, USA
I've done it manually using DiskPart.exe.
First, SELECT the VDISK:
SELECT file="C:\Program Files\Windows XP Mode\Windows XP Mode base.vhd"
Then ATTACH it :
ATTACH VDISK

You can also create VDISK's based on another VDISK using the CREATE command.

When done, you DETACH VDISK.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,923
51
Albuquerque, NM
prospero.unm.edu
I've done it manually using DiskPart.exe.
First, SELECT the VDISK:
SELECT file="C:\Program Files\Windows XP Mode\Windows XP Mode base.vhd"
Then ATTACH it :
ATTACH VDISK

You can also create VDISK's based on another VDISK using the CREATE command.

When done, you DETACH VDISK.
Neat; you could wrap that in a batch file. I've been using the Disk Management console, as I don't need to mount VHDs very often.
 
Here's the .CMD files that I have been using in TCC to Mount/Unmount VHDs;
Code:
REM https://gist.github.com/nicjansma/9b82f28a77f306b0cfc0
@echo off
setlocal enabledelayedexpansion

if {%1}=={} (
    echo Usage: %~nx0 [vhd] [letter]
    exit /b 1
)
set vhdPath=%~dpnx1
set driveLetter=%2

if {!driveLetter!}=={} (
    echo Mounting !vhdPath!
) else (
    echo Mounting !vhdPath! to !driveLetter!:
)

REM
REM create dispart script
REM
set diskPartScript=%~nx0.diskpart
echo sel vdisk file="!vhdPath!">!diskPartScript!
echo attach vdisk>>!diskPartScript!

REM assign the drive letter if requested
if not {!driveLetter!}=={} (
    echo select partition 1 >>!diskPartScript!
    echo assign letter=!driveLetter!>>!diskPartScript!
)

REM Show script
echo.
echo Running diskpart script:
type !diskPartScript!

REM
REM diskpart
REM
diskpart /s !diskPartScript!
del /q !diskPartScript!

echo Done!

endlocal
Code:
REM https://gist.github.com/nicjansma/9b82f28a77f306b0cfc0
@echo off
setlocal enabledelayedexpansion

if {%1}=={} (
    echo Usage: %~nx0 [vhd]
    exit /b 1
)
set vhdPath=%~dpnx1

echo Unmounting !vhdPath!

REM
REM create dispart script
REM
set diskPartScript=%~nx0.diskpart
echo sel vdisk file="!vhdPath!">!diskPartScript!
echo detach vdisk>>!diskPartScript!

REM
REM diskpart
REM
diskpart /s !diskPartScript!
del /q !diskPartScript!

echo Done!

endlocal
Joe