根据一定的时间间隔自动重启Windows服务

Gra*_*ton 2 windows windows-service

无论如何,在 Windows 机器上,是否可以自动重新启动某个 Windows 服务?

Nat*_*ley 5

快速而肮脏的方法是设置计划任务以运行以下命令行。

sc.exe stop <serviceName> && sc.exe start <serviceName>
Run Code Online (Sandbox Code Playgroud)

要创建此计划任务以通过命令行在每个午夜运行:

SCHTASKS /Create /TN "Restart Service"  /TR "sc.exe stop <serviceName> && sc.exe start <serviceName>" /SC DAILY /ST 00:00 /RU SYSTEM /F
Run Code Online (Sandbox Code Playgroud)

您当然可以在此过程中添加更多智能和日志记录。甚至可以围绕Get-Service CMDLet编写一个完整的Powershell脚本。如果您不想创建单独的本地帐户(首选)来运行此计划任务,则可以使用没有密码的帐户“系统”