The new service pack (SP1) for Microsoft Virtual Server 2005 R2 added some new functions to the COM API. There's too many to list, but the one i've found most useful allows you to return the guest machine's computer name as it appears on the network - very useful for automation scripts, or simply launching a Remote Desktop client (as i wanted).

Unfortunately the documentation on it isn't great and it took me a while to find it when using C#, (thanks mainly to a few emails to/from Ben aka "Virtual PC Guy" http://blogs.msdn.com/virtual_pc_guy). It turns out you need to cast the GuestOS property of the virtual machine to IVMGuestOS which allows you access to the .ComputerName property:

string name = ((IVMGuestOS2)Machine.GuestOS).ComputerName;
I then took the above to launch an RDP session

using (Process p = new Process())
{
    p.StartInfo.Arguments = string.Format(@"/v:{0} /console", name);
    p.StartInfo.FileName = Settings.Default.RDPPath;
    p.Start();
}

Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Tuesday, October 23, 2007 10:37 AM | in C# Microsoft Virtual Server 2005

Comments

Gravatar
# re: Using COM to get Virtual Machine's network name in C#
Posted by Vinay
on 11/9/2007 11:07 PM
For some reason, ((IVMGuestOS2)Machine.GuestOS).ComputerName returns an empty string for me. Any suggestions?
Gravatar
# re: Using COM to get Virtual Machine's network name in C#
Posted by manpreet
on 5/29/2008 8:21 AM
i need help in getting virtual machine's network name in c#

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 1 and 3 and type the answer here: