如何使用任务计划程序重新启动 Windows 服务 [英] How to restart a windows service using Task Scheduler

查看:129
本文介绍了如何使用任务计划程序重新启动 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最简单的方法是创建一个批处理文件:

The easiest way to do this is to create a batch file with:

NET stop <service name>
NET start <service name>

创建并测试批处理文件后,将其添加到 Windows 任务计划程序并以特定时间间隔运行.这里的问题是,当 bat 文件丢失或损坏时,服务不会重新启动.那么,是否有其他方法可以在特定时间间隔重新启动服务?

Once the batch file is created and tested, add it to Windows Task Scheduler and run it at a specific time interval. Problem here is, when the bat file is missing or corrupt, the service won't restart. So, are there other ways to restart a service at a specific time interval?

推荐答案

您可以简单地创建计划任务,而不是使用 bat 文件.大多数情况下,您只定义一个操作.在这种情况下,使用 NET 命令创建两个操作.第一个停止服务,第二个启动服务.给他们一个 STOPSTART 参数,后跟服务名称.

Instead of using a bat file, you can simply create a Scheduled Task. Most of the time you define just one action. In this case, create two actions with the NET command. The first one to stop the service, the second one to start the service. Give them a STOP and START argument, followed by the service name.

在本例中,我们重新启动了Printer Spooler 服务.

In this example we restart the Printer Spooler service.

NET STOP "Print Spooler" 
NET START "Print Spooler"

注意:不幸的是NET RESTART <服务名称> 不存在.

Note: unfortunately NET RESTART <service name> does not exist.

这篇关于如何使用任务计划程序重新启动 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆