命令行創建服務項: sc create
用法:
sc <server> create [service name] [binPath= ] <option1> <option2>...
選項:
注意: 選項名稱包括等號,等號和值之間需要一個空格。
type= <own|share|interact|kernel|filesys|rec|userown|usershare> (默認 = own)
start= <boot|system|auto|demand|disabled|delayed-auto> (默認 = demand)
error= <normal|severe|critical|ignore> (默認 = normal)
binPath= <.exe 文件的 BinaryPathName>
group= <LoadOrderGroup>
tag= <yes|no>
depend= <依存關系(以 / (斜杠)分隔)>
obj= <AccountName|ObjectName> (默認= LocalSystem)
DisplayName= <顯示名稱>
password= <密碼>
示例:將 Redis 添加到服務,以管理員身份運行命令提示符
sc create Redis6.2.6 binPath= "D:\Redis6.2.6\redis-server.exe --service-run \"D:\Redis6.2.6\redis-windows.conf\"" DisplayName= Redis6.2.6 start= auto
命令中的雙引號使用反斜杠加引號 \" 來進行轉義處理
設置服務的描述: sc description
用法:
sc <server> description [service name] [description]
示例:修改 Redis 描述
sc description Redis6.2.6 "This service runs the Redis server"