Charles Dye
Super Moderator
- May
- 5,328
- 161
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.)
By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!Oh. I had assumed that you were using OpenVirtualDisk() and AttachVirtualDisk(). Is there some other way?The last time I looked at this, there wasn't any API support for VHD / VHDX files.
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.
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
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