Skip to content

Instantly share code, notes, and snippets.

@17
Last active Jul 2, 2021
Embed
What would you like to do?
installing and removing a user-defined service.
@echo off
setlocal
set ServicePath=HKLM\System\CurrentControlSet\Services
if "%1"=="-i" goto :create
if "%1"=="-d" goto :delete
goto :usage
:create
(
md %windir%\system32\srvice\%2\ & copy /y srvany.exe %windir%\system32\srvice\%2\
sc query %2 || sc create %2 start= %3 binPath= %windir%\system32\srvice\%2\srvany.exe DisplayName= %2
reg add %ServicePath%\%2\Parameters /v Application /d %4 /f
reg add %ServicePath%\%2\Parameters /v AppDirectory /d %5 /f
if defined %6 reg add %ServicePath%\%2\Parameters /v AppParameters /d %6 /f
) 1>nul 2>nul
goto :done
:delete
(
sc query state= | find "%2" && sc stop %2
sc query %2 && sc delete %2
rd /q /s %windir%\system32\srvice\%2\
rd %windir%\system32\srvice\
) 1>nul 2>nul
goto :done
:usage
echo. Services Manager 0.1.0 - unmric
echo. Usage: srvmgr [-vadl?] [-i .. ] [-d ServiceName]
echo. Arguments:
echo. -i - Sends a Continue control request to a service.
echo. *ServiceName = (string)
echo. *StartType = (boot, system, auto, demand, disabled)
echo. *binPath = (string)
echo. *BinDirectory = (string)
echo. BinArguments = (string)
echo. -d - Deletes a service (from the registry).
echo. *ServiceName = (string)
echo. Examples:
echo. srvmgr -i test auto c:\test.exe c:\
echo. srvmgr -d test
goto Done
:done
endlocal
echo on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment