logo
tt's Note
运维
数据库
linux
vpn
日志
中间件
服务
监控
shell
windows
语言
云服务
其他
开发
工具
软件
浏览器
多端
win
mac
网站
项目
效率工具
兴趣
脚本
jenkins
数据库
linux
vpn
日志
中间件
服务
监控
shell
windows
语言
云服务
其他
工具
浏览器
多端
win
mac
网站
效率工具
兴趣
jenkins
logo
tt's Note
Windows概览
bat命令
开机启动
注册服务
Previous Page开机启动

#注册服务

#sc

#介绍

系统自带命令,Windows 原生工具。

功能是 创建、配置、删除、启动、停止服务。

当你 sc create 的时候,你必须指定一个 可执行文件(EXE),Windows 会把它注册为服务。

#使用

注册完服务就可以实现开机自启了

以windows_export为例

开源地址

#注册服务

@echo off
sc create windows_exporter binpath= C:\windows_exporter-0.18.1-amd64.exe type= own start= auto displayname= windows_exporter
pause

#在服务界面设置启动参数并启动

--telemetry.addr=0.0.0.0:9182

3、访问127.0.0.1:9182/metrics

#删除服务

sc delete windows_exporter

#nssm

#介绍

第三方工具,是一个“服务包装器”。

它能把 任意可执行程序(比如普通 exe,甚至 bat 脚本、python、java 命令)包装成 Windows 服务。

#安装

#使用

#注册服务

nssm install test_service "D:\app\test.bat" -d "D:\app"

#删除服务

nssm remove test_service confirm