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
- https://blog.csdn.net/achenyuan/article/details/87616324
- https://www.cnblogs.com/sheng-247/p/10528160.html