使用批处理删除/安装 Windows 服务
我有一个名为 serv1
的服务,我不知道它的状态(是否已安装),该服务是通过另一个批处理文件安装的(service.bat install
)
我的目标是编写一个 .bat
文件来检查 serv1
是否存在,因此我想删除它并重新创建 它调用“service.bat”安装
';如果没有,请调用“service.bat install
”创建它
我已经搜索了一些命令;我发现我们使用“ sc delete ServiceName
但是,我对批处理不太熟悉。
I've got a service called serv1
which I don't know it's state (already installed or not), this service gets installed via another batch file (service.bat install
)
My goal is to write a .bat
file which checks if serv1
exists, so I want to remove it and re-create it calling 'service.bat install
' ; if not, create it calling 'service.bat install
'
I've searched for some commands; I found that we use " sc delete ServiceName
but, I'm not familiar with batch a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望下面的bat脚本能够帮助到你。打开记事本;复制以下代码并将其粘贴到记事本中。使用 .bat 扩展名保存文件,例如“Helper.bat”。
现在打开命令提示符,导航到放置 Helper.bat(和您的 service.bat)的目录。然后写一个这样的命令
Helper.bat serv1
这是一个通用脚本,因此您需要将相关服务名称作为参数传递。否则,只需将 %1 替换为 serv1 即可完成您的工作!
如果您需要了解有关此脚本的更多信息,请随时询问我。
这是脚本:
I hope the following bat script will help you out. Open notepad; copy the following code and paste it in notepad. Save the file with .bat extension e.g. "Helper.bat".
Now open command prompt, navigate to the directory where Helper.bat (and your service.bat) are placed. Then write a command like this
Helper.bat serv1
This is a generic script so you need to pass the concerned service name as a parameter. Otherwise simply replace %1 with serv1 and get your work done!
If you need to know more about this script then feel free to ask me.
Here's the script: