Posts Tagged ‘Windows Service’

http://www.howtogeek.com/howto/windows-vista/how-to-delete-a-windows-service-in-vista-or-xp/

Sample .bat file code …

  1. To Set default name (%1 passed as parameter to bat file) while installing service
  2. Check to see service exist and uninstall it if it exist
  3. Re-install it with source type automatic
  4. Start the service after successful installation.

SET ServiceName=%1
IF [%ServiceName%]==[] SET ServiceName=DefaultServiceName
SET ServicePath=C:\Services\%ServiceName%
REM — CHECK IF SERCICE DOES NOT EXIST THEN DIRECTLY INSTALL THE SERVICE
SC QUERY %ServiceName%> NUL
IF ERRORLEVEL 1060 GOTO InstallAndStartService
REM – IF SERVICE IS NOT RUNNING THEN THEN DIRECTLY UNINSTALL THE SERVICE
sc query | find /I “%ServiceName%” > nul
if errorlevel 1 GOTO UnitallService
:StopService
echo Stopping the Sercive…
sc stop %ServiceName%
:UnitallService
echo Unintalling the service…
sc delete %ServiceName%
echo Press any key after 5 secondes
pause
:InstallAndStartService
echo Copying Files
IF EXIST %ServicePath% del %ServicePath% /Q
IF NOT EXIST %ServicePath% md %ServicePath%
Copy *.* %ServicePath%
echo Installing the service…
sc create %ServiceName% binPath= “%ServicePath%/ServiceName.exe %ServiceName%” start= auto
echo Starting the Service…
sc start %ServiceName%
echo Service has been installed successfully
pause

Open cmd with Run as administrator and run following command …

sc.exe delete ReportServer
sc.exe delete ReportServer$MSSQLSERVER