增加 Windows 服务控制。

Signed-off-by: rick.chan <cy@haoan119.com>
This commit is contained in:
rick.chan 2025-01-19 17:27:01 +08:00
parent 5c18018dcb
commit 7db919cf8e

View File

@ -0,0 +1,49 @@
# Windows 服务控制
可在开始菜单点击右键,进入“计算机管理”,在“服务和应用程序->服务”中查看和配置当前的系统服务。
## SC 命令
使用 SC 命令创建服务:
```bash
sc create <Service Name> start= <method> type= own binPath= "<Path and arguments>"
# 例如
sc create Gitea start= auto binPath= ""<绝对路径>\gitea.exe" web --config "<绝对路径>\custom\conf\app.ini""
```
- start:
- boot
- system
- auto: 自动启动这些服务会在Windows启动时自动启动无需用户登录。
- demand: 手动启动,这些服务需要在用户方便的时候手动启动或停止‌。
- disabled
- delayed-auto
启动服务:
```bash
sc start <Service Name>
```
配置服务:
```bash
sc config <Service Name> start= auto
sc config <Service Name> type= own
```
- type:
- own: 将服务配置为使用自己的进程运行,而不是共享进程。这可以提高服务的独立性。
停止服务:
```bash
sc stop <Service Name>
```
如不再需要,同样使用 SC 命令删除服务,删除服务前需先停止该服务。
```bash
sc delete <Service Name>
```