Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Done MOUNTISO: Add support for VHD / VHDX files

Charles Dye

Super Moderator
May
4,997
129
Staff member
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.)
 
The last time I looked at this, there wasn't any API support for VHD / VHDX files.
Oh. I had assumed that you were using OpenVirtualDisk() and AttachVirtualDisk(). Is there some other way?
 
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.
 
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
 

Similar threads

Back
Top