Relatively speaking, it is relatively common, if any man has a better way to achieve, or found that there are shortcomings, please advise.
@echo off
echo.--------------------------------------------------echo.----Technical support: CC--------echo.----Today is%date%.--------Echo.--------------------------------------------------echo. Detecting if the service is already created, please wait ... sc query Njfkreportanalyticalservice >nul && Goto:startserver | | goto:install:installset/p choice=windows The service is not installed, do you want to install it? Y (yes)/n (NO) Please select: if/i "%choice%" = = "Y" (SC create njfkreportanalyticalservice binpath= "%~dp0njfkreportanalytical.exe"Echo. ------------Service creation is complete. ------------Goto:StartServer:StartServerecho. Detecting service running status, please later ... net start|findstr/i/C: "Njfkreportanalyticalservice" >null && goto:stopserverset/p Choice=windows Open the Njfkreportanalyticalservice (Nanjing Message Resolution Service) service? Please select Y (yes)/n (NO): if/i "%choice%" = = "Y" (Echo. Service startup ...net start NjfkreportanalyticalserviceEcho. ------------Service is started------------Goto:configserver) if/i "%choice%" = = "n" Goto:noecho. Invalid input please reenter. Goto:funish:StopServerecho. Service running .... set/p choice=windows stop Njfkreportanalyticalservice (Nanjing Message parsing service)? Please select Y (yes)/n (NO): if/i "%choice%" = = "Y" (Echo. Service stopped ...net stop NjfkreportanalyticalserviceEcho. ------------Service is stopped------------Goto:funish) if/i "%choice%" = = "n" Goto:noecho. Input is not valid please re-enter.: configserverset/p Choice=windows is powered on with system Autorun? Please select Y (yes)/n (NO): if/i "%choice%" = = "Y" (echo. Service auto-open configuration ...sc config Njfkreportanalyticalservice start= AUTOecho.------------Auto-open configuration complete------------Goto:funish) if/i "%choice%" = = "n" Goto:no:funishecho. Operation completed &&goto:no:no Pause
There are a few small points to note, that is
1, determine if the service has been created
2. Determine the Windows service health status
3, about how to get the file path.
Windows services, install, start, stop, configure, a batch file to fix