public void StartVm(VmId vm, StartVmType type) { var typeFlag = ""; switch (type) { case StartVmType.Default: break; case StartVmType.Gui: typeFlag = "--type=gui"; break; case StartVmType.Headless: typeFlag = "--type=headless"; break; case StartVmType.Sdl: typeFlag = "--type=sdl"; break; case StartVmType.Separate: typeFlag = "--type=separate"; break; } // Typical stdout: // Waiting for VM "OpenBSD 64-bit" to power on... // VM "OpenBSD 64-bit" has been successfully started. // Note that the system has not finished booting by the time this returns! var exit = Proc.ExecIn(null, VBoxManagePath, $"startvm {vm} {typeFlag}", stdout => { }, stderr => { }, ProcessWindowStyle.Hidden); if (exit != 0) { throw new ToolResultSyntaxException("VBoxManage startvm ...", "Returned nonzero"); } }
public bool TryStartVm(VmId vm, StartVmType type) { try { StartVm(vm, type); return(true); } catch (VmManagementException) { return(false); } }