Question

I want to extract a file from vhdx file. There is a way to do this. -Mount the disk and read file from mounted location. But I want to write a CPP/C# code for this. I am able to get vhdx file details with MS provided API (visrtdisk.dll) which consists files size, GUID, etc, but I am not getting any API which can give me the disk structure (MBE/Partitions/FileSystem/etc) from given vhdx file.

Was it helpful?

Solution

Please see this C# library http://discutils.codeplex.com/, it is very comprehensive library and supports lot of file systems (including VHD, VHDx, ISO, EXT, HFS, HFSPlus etc.)

[The sample taken from home page and modified it for vhdx instead of vhd].

long diskSize = 30 * 1024 * 1024; //30MB
using (Stream vhdStream = File.Create(@"C:\TEMP\mydisk.vhdx"))
{
    Disk disk = Disk.InitializeDynamic(vhdStream, diskSize);
    BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsFat);
    using (FatFileSystem fs = FatFileSystem.FormatPartition(disk, 0, null))
    {
        fs.CreateDirectory(@"TestDir\CHILD");
        // do other things with the file system...
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top