Batch bat registered as a windows service

This blog belongs to the original author without permission prohibited reproduced, please respect the original! If you have questions, please contact QQ509961766

Preparation Tool

Download Instsrv.exe and Srvany.exe

  • Instsrv.exe system is to install and remove services
  • Srvany.exe is to allow the program to run as a service

Edit bat

Here is a batch file: startRedisSentinel.bat (This is a startup file redis Sentinel mechanisms)

@echo off
redis-server.exe sentinel.conf --sentinel 
@pause

Add Service

Start with Administrator cmd, enter the command: instsrv.exe service name srvany.exe
example: D: \ gateway \ Bat2Server \ instsrv.exe Sentinel D: \ gateway \ Bat2Server \ srvany.exe
Here Insert Picture Description
Print Services has been successfully added shows a success!

Configuration parameters

  • Open the Registry (win + r run regedit)
  • Search Path: HKEY_LOCAL_MACHINE / SYSTEM / CurrentControlSet / Services / Sentinel
  • Right-click on the folder Sentinel New Item: Parameters and add two parameters of type string in the right side of the space to the right child Parameters: AppDirectory and Application, and specify parameter values
//bat文件所在文件主路径
AppDirectory = "D:\gateway\Redis-3.2.100"
//bat文件路径
Application = "D:\gateway\Redis-3.2.100\startRedisSentinel.bat"

Here Insert Picture Description

Start Service

View the list of services (win + r run services.msc), start the Sentinel Services
Here Insert Picture Description

Delete Service

Cmd command administrator rights, Format: instsrv.exe service name remove
For example: D: \ gateway \ Bat2Server \ instsrv.exe Sentinel remove

Published 75 original articles · won praise 44 · views 510 000 +

Guess you like

Origin blog.csdn.net/u013254183/article/details/90482972