public override void StartVMProcess(string BinaryPath, string[] args, bool hidden, int timeout) { VMObjects vo = Instanciate(); IGuestProcess ip = null; ip = vo.GSession.ProcessCreate(BinaryPath, args, new string[] { }, new ProcessCreateFlag[] { hidden?ProcessCreateFlag.ProcessCreateFlag_Hidden: ProcessCreateFlag.ProcessCreateFlag_None }, (uint)timeout); //ip.WaitFor((uint)ProcessWaitForFlag.ProcessWaitForFlag_Terminate, (uint)timeout); releaseObjects(vo); }
public override void SuspendVM() { VMObjects vo = Instanciate(); if (machine.State == MachineState.MachineState_Running) { vo.Console.PowerDown().WaitForCompletion(40000); } releaseObjects(vo); }
public override void CopyFileFromHost(string HostPath, string VMPath) { VMObjects vo = Instanciate(); IProgress ip = vo.GSession.CopyTo(HostPath, VMPath, new CopyFileFlag[] { CopyFileFlag.CopyFileFlag_None }); ip.WaitForCompletion(-1); releaseObjects(vo); if (ip.ErrorInfo != null) { throw new Exception(ip.ErrorInfo.Text); } }
public override void KillVMProcess(string ProcessName) { VMObjects vo = Instanciate(); foreach (var proc in vo.GSession.Processes) { if (proc.Name == ProcessName) { proc.Terminate(); } } releaseObjects(vo); }
private void releaseObjects(VMObjects vo) { try { vo.GSession.Close(); } catch (Exception) { } if (vo.Session.State == SessionState.SessionState_Locked) { vo.Session.UnlockMachine(); } }
public override void RevertSnapshotVM(string SnapshotName) { SuspendVM(); VMObjects vo = Instanciate(); //vo.Session = new SessionClass(); //machine.LockMachine(vo.Session, LockType.LockType_Shared); //vo.Console = vo.Session.Console; var snapshot = machine.FindSnapshot(SnapshotName); var prog = vo.Console.RestoreSnapshot(snapshot); prog.WaitForCompletion(100000); //vo.Session.UnlockMachine(); releaseObjects(vo); }
private VMObjects Instanciate() { VMObjects vo = new VMObjects(); vo.Session = new SessionClass(); machine.LockMachine(vo.Session, LockType.LockType_Shared); vo.Console = vo.Session.Console; try { vo.GSession = vo.Console.Guest.CreateSession(username, password, domain, "ViniSandbox"); } catch (Exception) { } return(vo); }
public override void StartVMProcess(string BinaryPath, string[] args, bool hidden, int timeout, Mutex m) { VMObjects vo = Instanciate(); IGuestProcess ip = null; ip = vo.GSession.ProcessCreate(BinaryPath, args, new string[] { }, new ProcessCreateFlag[] { hidden?ProcessCreateFlag.ProcessCreateFlag_Hidden: ProcessCreateFlag.ProcessCreateFlag_None }, (uint)timeout); m.ReleaseMutex(); ip.WaitFor((uint)ProcessWaitForFlag.ProcessWaitForFlag_Terminate, (uint)timeout); releaseObjects(vo); /*VMObjects vo = Instanciate(); * var ret = vo.GSession.ProcessCreate(BinaryPath, args, new string[] { }, new ProcessCreateFlag[] { hidden ? ProcessCreateFlag.ProcessCreateFlag_Hidden : ProcessCreateFlag.ProcessCreateFlag_None }, (uint)timeout); * m.ReleaseMutex(); * if(ret.Status == ProcessStatus.ProcessStatus_Started || ret.Status == ProcessStatus.ProcessStatus_Starting) * ret.WaitFor((uint)ProcessWaitForFlag.ProcessWaitForFlag_Terminate, (uint)timeout); * releaseObjects(vo); * if (ret.Status == ProcessStatus.ProcessStatus_Error) * throw new Exception("Error on start process " + BinaryPath);*/ }