/// <summary> /// 卸载 Windows 服务 /// </summary> /// <param name="serviceName"></param> public static void UninstallWinService(string serviceName) { var installUtil = $@"{GetDotNetFolder()}\InstallUtil.exe"; if (!CheckServiceIsExist(serviceName)) { return; } YUtil.Exec(installUtil, "/u " + serviceName); }
/// <summary> /// 安装 Windows 服务 /// </summary> /// <param name="servicePath"></param> /// <param name="serviceName"></param> public static void InstallWinService(string servicePath, string serviceName) { var installUtil = $@"{GetDotNetFolder()}\InstallUtil.exe"; //服务已经安装了 if (CheckServiceIsExist(serviceName)) { return; } //执行安装操作 YUtil.Exec(installUtil, servicePath); }
/// <summary> /// 通过NirCmd调用的方式打开显示器 /// 暂时不支持 Win10 /// </summary> /// <param name="nirCmdPath"></param> public static void OpenScreen(string nirCmdPath) { if (YUtil.GetOsVersion().Contains(Windows10)) { Console.WriteLine("暂不支持win10的开启屏幕操作"); return; } var task = Task.Run(() => { Exec(nirCmdPath, "monitor on"); }); //1秒超时,之前有卡死的bug,目前这样修复 task.Wait(1000); }
/// <summary> /// 可控制 Interval 的次数 /// </summary> /// <param name="interval"></param> /// <param name="action"></param> /// <param name="cycleTimes"></param> /// <returns></returns> public static Timer SetInterval(double interval, Action <int> action, int cycleTimes) { Timer timer = new Timer(interval); int times = 0; timer.Elapsed += (s, e) => { if (++times <= cycleTimes) { action(times); } else { YUtil.ClearTimeout(timer); } }; RecoveryTimeout(timer); return(timer); }