public static void CallAdminProcess(params string[] args) { var d = FileIO.GetTemporaryDirectory(); var exepath = Path.Combine(d, "adminprocess.exe"); File.WriteAllBytes(exepath, Resources.adminprocess); var p = new Process { StartInfo = { CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = true, FileName = exepath, Verb = "runas", Arguments = string.Join(" ", args) } }; Utils.WaitWhile(() => !File.Exists(p.StartInfo.FileName)); try { p.Start(); } catch (Win32Exception e) when(e.NativeErrorCode == WinError.ERROR_CANCELLED) { throw new OperationCanceledException(Strings.OpCancelled, e); } p.WaitForExit(); FileIO.SafeDel(d); }
public SevenZipExtractor() { var d = FileIO.GetTemporaryDirectory(); SevenZipPath = Path.Combine(d, "7za.exe"); File.WriteAllBytes(SevenZipPath, Resources._7za); }
public static void LaunchQemu(string iso, bool usb = false) { var f = FileIO.GetTemporaryDirectory(); Paths.Add(f); var floppy = Path.GetExtension(iso).ToLower() == ".img"; var ext = new SevenZipExtractor(); File.WriteAllBytes(Path.Combine(f, "qemutmp.7z"), Resources.qemu); ext.Extract(Path.Combine(f, "qemutmp.7z"), f); var p = new Process { StartInfo = { UseShellExecute = false }, EnableRaisingEvents = true }; p.StartInfo.FileName = Path.Combine(f, "qemu.exe"); p.StartInfo.WorkingDirectory = f; p.StartInfo.Arguments = " -m 1536 -M pc -cpu max "; if (usb) { var logicalDiskId = iso.Substring(0, 2); var deviceId = DriveIO.GetPhysicalPath(logicalDiskId); p.StartInfo.Arguments += "-boot c -drive file=" + deviceId + ",if=ide,index=0,media=disk,format=raw "; p.StartInfo.UseShellExecute = true; p.StartInfo.Verb = "runas"; } else { p.StartInfo.Arguments += (floppy ? "-boot a -fda" : "-boot d -cdrom") + " \"" + iso + "\""; } Utils.WaitWhile(() => !File.Exists(p.StartInfo.FileName)); p.Start(); ext.Close(); p.Exited += (sender, args) => { FileIO.SafeDel(f); Paths.Remove(f); }; }