将bat文件或exe程序注册成windows服务

bat文件或exe程序注册成windows服务

命令行使用sc命令.

关于sc命令的详解,请自行查看帮助(sc /?)

在此只简单提及如何加入系统服务功能.
注意要在系统自带CMD里执行

  • 加入服务:
sc create ServiceName binPath= 路径 start= auto

(等号后面的空格必须) why,

  • 删除服务:
sc delete ServiceName

示例:

# 将Tomcat加入到系统服务中
sc create Tomcat binPath= F:/tomcat/bin/startup.bat start= auto
# 查看方式:我的电脑 -> 右键 -> 管理 -> 服务和应用程序 -> 服务 -> 右窗口直接搜索
# 将Tomcat服务删除:
sc delete Tomcat

**注意:**等号和值之间应该有一个空格

示例2:路径有空格时,使用双引号

sc create MyService binPath= "cmd.exe /c start c:\a.exe" start= auto displayname= "AutoStartOracle Services"

Bat后台运行

在你写的批处理文件,开头加上以下三行代码即可

@echo off 
if "%1" == "h" goto begin 
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit 
:begin 
  • 示例2:
if "%1"=="hide" goto begin 
start mshta vbscript:createobject("wscript.shell").run("""%~0"" hide",0)(window.close)&&exit
:begin 
  1. https://blog.csdn.net/achenyuan/article/details/87616324
  2. https://www.cnblogs.com/sheng-247/p/10528160.html

Windows 无法启动xx服务 错误1053

https://blog.csdn.net/u012260672/article/details/86602642

参考

  1. https://www.cnblogs.com/yepei/p/6218887.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值