コード例 #1
0
 public static Task BlockWAU()
 {
     return(Task.Factory.StartNew(() => {
         ExtractBlockWAUManifestResource();
         Cmd.RunClose(EntryAssemblyInfo.BlockWAUFileFullName, string.Empty, waitForExit: true);
     }));
 }
コード例 #2
0
ファイル: TaskKill.cs プロジェクト: zheng9980419/ntminer
 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);
 }
コード例 #3
0
ファイル: TaskKill.cs プロジェクト: zheng9980419/ntminer
 public static void Kill(string processName)
 {
     if (string.IsNullOrEmpty(processName))
     {
         return;
     }
     Cmd.RunClose($"taskkill /F /T /IM {processName}.exe", string.Empty);
 }
コード例 #4
0
ファイル: TaskKill.cs プロジェクト: ayxcjqx/ntminer
 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);
 }
コード例 #5
0
ファイル: TaskKill.cs プロジェクト: yuanaichi/ntminer
 /// <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 {
     }
 }
コード例 #6
0
 /// <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 {
     }
 }
コード例 #7
0
ファイル: TaskKill.cs プロジェクト: yuanaichi/ntminer
 /// <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 {
     }
 }
コード例 #8
0
ファイル: WindowsUtil.cs プロジェクト: bentiancai629/ntminer
 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);
     }
 }
コード例 #9
0
ファイル: WindowsUtil.cs プロジェクト: yuanaichi/ntminer
 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失败"));
     }
 }
コード例 #10
0
 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);
         }
     });
 }
コード例 #11
0
 /// <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 {
     }
 }
コード例 #12
0
 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);
     }
 }
コード例 #13
0
 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);
     }
 }
コード例 #14
0
ファイル: TaskKill.cs プロジェクト: piaoyun/ntminer
 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);
     }
 }
コード例 #15
0
 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);
     }
 }
コード例 #16
0
 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);
     }
 }
コード例 #17
0
ファイル: Firewall.cs プロジェクト: TimeYM/ntminer
 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);
     }
 }
コード例 #18
0
ファイル: Firewall.cs プロジェクト: zheng9980419/ntminer
 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);
     }
 }
コード例 #19
0
 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);
     }
 }
コード例 #20
0
ファイル: TaskKill.cs プロジェクト: piaoyun/ntminer
 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);
     }
 }
コード例 #21
0
ファイル: Power.cs プロジェクト: zylx0532/NtMiner
 public static void Restart(int delaySeconds = 0)
 {
     Cmd.RunClose("shutdown", "-r -f -t " + delaySeconds);
 }
コード例 #22
0
ファイル: Power.cs プロジェクト: zylx0532/NtMiner
 public static void Shutdown(int delaySeconds = 0)
 {
     Cmd.RunClose("shutdown", "-s -f -t " + delaySeconds);
 }
コード例 #23
0
 public static void Shutdown()
 {
     Cmd.RunClose("shutdown", "-s -f -t 0");
 }
コード例 #24
0
 public static void Restart()
 {
     Cmd.RunClose("shutdown", "-r -f -t 0");
 }