public static Task BlockWAU() { return(Task.Factory.StartNew(() => { ExtractBlockWAUManifestResource(); Cmd.RunClose(EntryAssemblyInfo.BlockWAUFileFullName, string.Empty, waitForExit: true); })); }
public static void KillOtherProcess(Process process) { if (process == null) { return; } Cmd.RunClose($"taskkill /F /FI \"pid ne {process.Id}\" /T /IM {process.ProcessName}.exe", string.Empty); }
public static void Kill(string processName) { if (string.IsNullOrEmpty(processName)) { return; } Cmd.RunClose($"taskkill /F /T /IM {processName}.exe", string.Empty); }
public static void Kill(string processName, bool waitForExit = false) { if (string.IsNullOrEmpty(processName)) { return; } Cmd.RunClose($"taskkill /F /T /IM {processName}.exe", string.Empty, waitForExit); }
/// <summary> /// 不会抛出异常,因为吞掉了异常 /// </summary> /// <param name="process"></param> /// <param name="waitForExit"></param> public static void KillOtherProcess(Process process, bool waitForExit = false) { if (process == null) { return; } try { string args = $"/F /FI \"pid ne {process.Id}\" /T /IM {process.ProcessName}.exe"; Cmd.RunClose("taskkill", args, waitForExit); Write.DevDebug(args); } catch { } }
/// <summary> /// 不会抛出异常,因为吞掉了异常 /// </summary> public static void Kill(int pid, bool waitForExit = false) { try { if (pid <= 0) { return; } string args = $"/F /T /PID {pid.ToString()}"; Cmd.RunClose("taskkill", args, waitForExit); Write.DevDebug(args); } catch { } }
/// <summary> /// 不会抛出异常,因为吞掉了异常 /// </summary> /// <param name="processName"></param> /// <param name="waitForExit"></param> public static void Kill(string processName, bool waitForExit = false) { try { if (string.IsNullOrEmpty(processName)) { return; } string args = $"/F /T /IM {processName}.exe"; Cmd.RunClose("taskkill", args, waitForExit); Write.DevDebug(args); } catch { } }
public static void BlockWAU() { try { Task.Factory.StartNew(() => { Type type = typeof(WindowsUtil); Assembly assembly = type.Assembly; string name = "BlockWAU.bat"; string fileFullName = Path.Combine(SpecialPath.TempDirFullName, name); assembly.ExtractManifestResource(type, name, fileFullName); Cmd.RunClose(fileFullName, string.Empty, waitForExit: false); }); } catch (Exception e) { Logger.ErrorDebugLine(e); } }
public static void Win10Optimize() { try { Task.Factory.StartNew(() => { Type type = typeof(WindowsUtil); Assembly assembly = type.Assembly; string name = "Win10Optimize.reg"; string fileFullName = Path.Combine(SpecialPath.TempDirFullName, name); assembly.ExtractManifestResource(type, name, fileFullName); Cmd.RunClose("regedit", $"/s \"{fileFullName}\"", waitForExit: true); VirtualRoot.Happened(new Win10OptimizeEvent(true, "优化Windows成功")); }); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.Happened(new Win10OptimizeEvent(false, "优化Windows失败")); } }
public static void Win10Optimize(Action <Exception> callback) { Task.Factory.StartNew(() => { try { Type type = typeof(WindowsUtil); Assembly assembly = type.Assembly; string name = "Win10Optimize.reg"; string fileFullName = Path.Combine(EntryAssemblyInfo.TempDirFullName, name); assembly.ExtractManifestResource(type, name, fileFullName); Cmd.RunClose("regedit", $"/s \"{fileFullName}\"", waitForExit: true); callback?.Invoke(null); } catch (Exception e) { callback?.Invoke(e); } }); }
/// <summary> /// 不会抛出异常,因为吞掉了异常 /// </summary> public static void Kill(string processName, bool waitForExit = false) { try { if (string.IsNullOrEmpty(processName)) { return; } if (!processName.EndsWith(".exe")) { processName += ".exe"; } string args = $"/F /T /IM {processName}"; Cmd.RunClose("taskkill", args, waitForExit); NTMinerConsole.DevDebug(args); } catch { } }
public static void Win10Optimize() { try { Task.Factory.StartNew(() => { Type type = typeof(WindowsUtil); Assembly assembly = type.Assembly; string name = "Win10Optimize.reg"; string fileFullName = Path.Combine(MainAssemblyInfo.TempDirFullName, name); assembly.ExtractManifestResource(type, name, fileFullName); Cmd.RunClose("regedit", $"/s \"{fileFullName}\"", waitForExit: true); VirtualRoot.ThisWorkerInfo(nameof(WindowsUtil), "优化Windows成功", OutEnum.Success); }); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisWorkerError(nameof(WindowsUtil), "优化Windows失败", OutEnum.Warn); } }
public static void BlockWAU() { try { Task.Factory.StartNew(() => { Type type = typeof(WindowsUtil); Assembly assembly = type.Assembly; string name = "BlockWAU.bat"; string fileFullName = Path.Combine(MainAssemblyInfo.TempDirFullName, name); assembly.ExtractManifestResource(type, name, fileFullName); Cmd.RunClose(fileFullName, string.Empty, waitForExit: true); VirtualRoot.ThisWorkerInfo(nameof(WindowsUtil), "禁用windows系统更新成功", OutEnum.Success); }); } catch (Exception e) { VirtualRoot.ThisWorkerError(nameof(WindowsUtil), "禁用windows系统更新失败", OutEnum.Warn); Logger.ErrorDebugLine(e); } }
public static void Kill(string processName) { if (string.IsNullOrEmpty(processName)) { return; } try { Process[] processes = Process.GetProcessesByName(processName); if (processes != null && processes.Length != 0) { foreach (var process in processes) { try { if (process.CloseMainWindow()) { Global.Logger.InfoDebugLine("CloseMainWindow成功杀死进程"); continue; } } catch (System.Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } try { process.Kill(); process.WaitForExit(10 * 1000); Global.Logger.InfoDebugLine("Kill成功杀死进程"); continue; } catch (System.Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } } processes = Process.GetProcessesByName(processName); if (processes != null && processes.Length != 0) { Cmd.RunClose($"taskkill /F /T /IM {processName}.exe", string.Empty); } } } catch (System.Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } }
public static bool PowerCfgOff() { try { int exitcode = -1; Cmd.RunClose("powercfg", "-h off", ref exitcode); bool r = exitcode == 0; if (r) { Logger.OkDebugLine("powercfg -h off ok"); } else { Logger.WarnDebugLine("powercfg -h off failed, exitcode=" + exitcode); } return(r); } catch (Exception e) { Logger.ErrorDebugLine("powercfg -h off failed,因为异常", e); return(false); } }
public static bool IgnoreAllFailures() { try { int exitcode = -1; Cmd.RunClose("bcdedit", "/set {current} bootstatuspolicy ignoreallfailures", ref exitcode); bool r = exitcode == 0; if (r) { Logger.OkDebugLine("bootstatuspolicy ignoreallfailures ok"); } else { Logger.WarnDebugLine("bootstatuspolicy ignoreallfailures faild, exitcode=" + exitcode); } return(r); } catch (Exception e) { Logger.ErrorDebugLine("bootstatuspolicy ignoreallfailures failed,因为异常", e); return(false); } }
public static bool DisableFirewall() { try { int exitcode = -1; Cmd.RunClose("netsh", "advfirewall set allprofiles state off", ref exitcode); bool r = exitcode == 0; if (r) { Global.DebugLine("disable firewall ok", ConsoleColor.Green); } else { Global.DebugLine("disable firewall failed, exitcode=" + exitcode, ConsoleColor.Red); } return(r); } catch (Exception e) { Global.Logger.Error("disable firewall failed,因为异常", e); return(false); } }
public static bool DisableFirewall() { try { int exitcode = -1; Cmd.RunClose("netsh", "advfirewall set allprofiles state off", ref exitcode); bool r = exitcode == 0; if (r) { Logger.OkDebugLine("disable firewall ok"); } else { Logger.WarnDebugLine("disable firewall failed, exitcode=" + exitcode); } return(r); } catch (Exception e) { Logger.ErrorDebugLine("disable firewall failed,因为异常", e); return(false); } }
public static bool IgnoreAllFailures() { try { int exitcode = -1; Cmd.RunClose("bcdedit", "/set {current} bootstatuspolicy ignoreallfailures", ref exitcode); bool r = exitcode == 0; if (r) { Global.DebugLine("bootstatuspolicy ignoreallfailures ok", ConsoleColor.Green); } else { Global.DebugLine("bootstatuspolicy ignoreallfailures faild, exitcode=" + exitcode, ConsoleColor.Red); } return(r); } catch (Exception e) { Global.Logger.Error("bootstatuspolicy ignoreallfailures failed,因为异常", e); return(false); } }
public static void Kill(int processId) { if (processId <= 0) { return; } try { Process process = Process.GetProcessById(processId); if (process != null) { try { if (process.CloseMainWindow()) { Global.Logger.InfoDebugLine("CloseMainWindow成功杀死进程"); return; } } catch (System.Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } try { process.Kill(); process.WaitForExit(10 * 1000); Global.Logger.InfoDebugLine("Kill成功杀死进程"); return; } catch (System.Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } Cmd.RunClose($"taskkill /F /T /PID {processId}", string.Empty); } } catch (System.Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } }
public static void Restart(int delaySeconds = 0) { Cmd.RunClose("shutdown", "-r -f -t " + delaySeconds); }
public static void Shutdown(int delaySeconds = 0) { Cmd.RunClose("shutdown", "-s -f -t " + delaySeconds); }
public static void Shutdown() { Cmd.RunClose("shutdown", "-s -f -t 0"); }
public static void Restart() { Cmd.RunClose("shutdown", "-r -f -t 0"); }