Hyper-V Program Manager
One of the coolest things (IMHO) about Virtual Server is that we have a completely documented COM API that allows end users and other developers to create programs that automate and interact with Virtual Server. Unfortunately doing this from a managed application (VB.Net or C#) is not the easiest thing to do. The reason for this is that there are two main complications that you have to deal with before you can get going.
The first complication is handling COM security levels. Calling the Virtual Server COM interfaces requires that your application be running with a COM security level of ‘impersonation’ (or higher). It is possible to do this from a managed application by using CoInitializeSecurity() - however it is only possible for an application to call CoInitializeSecurity() once – and the first call applies to the entire application. The problem starts when you realize that many components will attempt to call CoInitializeSecurity() for you – with the wrong COM security level (Even using the VMRC ActiveX control in your application will cause this to happen).
Thankfully - this is fairly easy to deal with - if you know what you are doing. First - there is sample code in the Virtual Server Programmers guide that shows you how to do this (be warned that this sample code has some typographical errors in it - but they are fairly easy to figure out). You should be able to take this code and use it directly - but if you are programming in VB.Net (my preferred managed language - yes I know that this will divide my reading audience :) I recommend that you put this sample code in a separate class - rather than a separate module (for reasons that I will discuss next week).
Once you have done this - you can simply call this class to initialize COM security as part of a shared main subroutine - ensuring that you get in first. There are two remaining problems that you should be aware of though:
Finally you should know that calling CoInitializeSecurity will mean that your program will require unmanaged code privileges.