0

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 help or regular .NET API calls like File.ReadAllText, Directory.GetDirectories and so on.

A sample code would be very appreciated.

Alex
  • 1,357
  • 3
  • 18
  • 41
  • Are you trying to access the drives that the Virtual Machine sees, or the hosting machines drives? If you want to do the second, I don't believe that is possible... – JasCav Mar 04 '11 at 22:15
  • I would like to access virtual drives from the host machine. I want to do that without virtual machine switched on. Why not possible? Virtual PC somehow does it itself so it should be possible for my program too. – Alex Mar 04 '11 at 23:04

2 Answers2

1

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.

Community
  • 1
  • 1
Forgotten Semicolon
  • 13,909
  • 2
  • 51
  • 61
  • Yes, I am going to support the two formats in my program. I would like to avoid third-party programs. If possible, I'd like to use .NET API. I am not sure about VMWare, but do not believe that Microsoft did not support their own technology with their own API on their own .NET. – Alex Mar 04 '11 at 22:41
  • @Alex you should not avoid third-party tools if they solve the task. +1 for answer, it is really cool, especially second link, there is great information there. – Andrey Mar 04 '11 at 23:04
  • Thanks, Andrey - will pay more attention to the second link. – Alex Mar 04 '11 at 23:09
  • I found a freeware tool for mounting VHD http://arainia.com/software/gizmo/download.html – Alex Mar 05 '11 at 20:48
1

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.

telewin
  • 1,102
  • 8
  • 17