eldadc
Contributor
Contributor

c# - StartProgramInGuest

Hi,

I'm very confused with VI API, I'm trying to set a startprogram in guest and I got stuck with diffrent object types, Can somebody please have a look on that.:

List<VirtualMachine> lstVirtualMachines = new List<VirtualMachine>();
            NameValueCollection vmFilter = new NameValueCollection();
            ManagedObjectReference DcMoRef = new ManagedObjectReference();
            GuestOperationsManager guOP = new GuestOperationsManager(vimClient, DcMoRef);
         
            NamePasswordAuthentication auth = new NamePasswordAuthentication();
            auth.Username = "xyz";
            auth.Password = "abc";
            auth.InteractiveSession = true;
            GuestProgramSpec progSpec = new GuestProgramSpec();
            progSpec.ProgramPath = "C:\\WINDOWS\\NOTEPAD.EXE";
            progSpec.Arguments = "";
            GuestProcessManager GuPr = new GuestProcessManager(vimClient, DcMoRef);
           VirtualMachine virtualmachine = (VirtualMachine)vimClient.FindEntityView(typeof(VirtualMachine), DcMoRef, vmFilter, null);
           long poid = GuPr.StartProgramInGuest(DcMoRef, auth, progSpec);

I'm not sure where I doing wrong , Can somebody help me please.

Thanks

0 Kudos
1 Reply
shluvme
Contributor
Contributor

   private void RunProgramInGuest(VimService service, string vmKey, string username, string password, string programPath, string arguments)
  
{
  
var auth = new NamePasswordAuthentication { username = username, password = password, interactiveSession = false };
  
var vmRef = new ManagedObjectReference { type = "VirtualMachine", Value = vmKey };
  
var progSpec = new GuestProgramSpec { programPath = programPath, arguments = arguments };
  
var processMgr = new ManagedObjectReference { type = "GuestProcessManager", Value = "guestOperationsProcessManager" };
  
var result = service.StartProgramInGuest(processMgr, vmRef, auth, progSpec);
  
}

0 Kudos