Using COM to get Virtual Machine's network name in C#

by Brad 23. October 2007 09:37
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();
}

Tags:

C# | Microsoft Virtual Server 2005

Comments

11/9/2007 11:07:37 PM #

For some reason, ((IVMGuestOS2)Machine.GuestOS).ComputerName returns an empty string for me. Any suggestions?

Vinay |

5/29/2008 7:21:14 AM #

i need help in getting virtual machine's network name in c#

manpreet |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar