In my C# 3.5 program I would like to access NTFS/FAT drives from MS Virtual PC machine.
I can see some C++ API for Virtual PC on the Microsoft site, but cannot find .NET one (should I use P-Invoke?). I would like to examine files and folders within filesystem inside the virtual michine with the hel开发者_StackOverflowp or regular .NET API calls like File.ReadAllText, Directory.GetDirectories and so on.
A sample code would be very appreciated.
Depending on the host operating system, you can use the Virtual Harddisk API introduced in Windows 7 / Server 2008. I'm not aware of .NET support for it. As far as I know, you will have to use interop to access it.
You can find an example in http://www.jmedved.com/2009/05/open-and-attach/, which defines only the structs/functions that are absolutely needed for attaching a VHD. A more complete interop definition class can be found in http://files.codes-sources.com/fichier_fullscreen.aspx?id=50320 (see the Win7_VirtualDiskWrapper/VirtualDiskWrapper/Interop) directory.
Note that using this API requires administrative privileges.
If your application should run on OSes older than Win7, then to the best of my knowledge you must use an external tool as described in replies/comments here.
Seems like a similar question to your VMDK question...
Anyway, you could use something like WinMount($) to mount the image, and then access it as you would any other local drive.
Another option is VHDMount, if you have MS Virtual Server.
Both have a commandline tool, which could be initiated from within an app if that is the need.
精彩评论