public void ControlVm(VmId vm, ControlVmType type) { string args = null; switch (type) { case ControlVmType.AcpiPowerButton: args = $"controlvm {vm} acpipowerbutton"; break; case ControlVmType.PowerOff: args = $"controlvm {vm} poweroff"; break; } if (args == null) { throw new ArgumentOutOfRangeException(nameof(type), "ControlVm passed invalid ControlVmType enumeration value"); } var exit = Proc.ExecIn(null, VBoxManagePath, args, stdout => { }, stderr => { }, ProcessWindowStyle.Hidden); if (exit != 0) { throw new ToolResultSyntaxException("VBoxManage controlvm ...", "Returned nonzero"); } }
public bool TryControlVm(VmId vm, ControlVmType type) { try { ControlVm(vm, type); return(true); } catch (VmManagementException) { return(false); } }