@echo off
set desdir=%ProgramFiles%\BlockSleepService
set currentPath=%~dp0
set serviceName="BlockSleepService"
sc query %serviceName% > nul
if %ERRORLEVEL% ==1060 (goto notexist)
goto exist
:exist
rem ----------------stop service------------
sc stop %serviceName%
rem ----------------create folder path------------
if exist "%desdir%" (echo exist) else (md "%desdir%")
echo "%currentPath%SystemService\bin\Release\SystemService.exe" "%desdir%"
rem ----------------copy file------------
xcopy "%currentPath%SystemService\bin\Release\SystemService.exe" "%desdir%" /Y
goto end
:notexist
rem ----------------create folder path------------
if exist "%desdir%" (echo exist) else (md "%desdir%")
echo "%currentPath%SystemService\bin\Release\SystemService.exe" "%desdir%"
rem ----------------copy file------------
xcopy "%currentPath%SystemService\bin\Release\SystemService.exe" "%desdir%" /Y
set targetfile=SystemService.exe
echo "%systemroot%/microsoft.net/framework/v4.0.30319/InstallUtil.exe" "%desdir%/%targetfile%"
rem ----------------install service------------
"%systemroot%/microsoft.net/framework/v4.0.30319/InstallUtil.exe" "%desdir%/%targetfile%"
rem ----------------uninstall service------------
rem "%systemroot%/microsoft.net/framework/v4.0.30319/InstallUtil.exe" /u "%desdir%/%targetfile%"
if %ERRORLEVEL% == 0 (goto end) else (goto exception)
:exception
pause
:end
sc start %serviceName%
pause
exit