Updating a Windows Service via a batch file

If you’ve written a Windows service, and you need to update it, perhaps with a bug fix, you’ll find that the process is very cumbersome, you need to stop the service, uninstall it, pull your changes, install it again, configure the service, then start the service.

This procedure, although not difficult, can eat away 15 minutes of development time on every update, and slows the fix/release cycle.

This is where I created a windows batch file, that does these steps in sequence, to save lots of time.

@echo off
REM – ADMIN ACCESS IS REQUIRED
REM – MAKE SURE LATEST CHANGES ARE CHECKED IN TO GIT, THIS CODE WILL UNDO UNCOMMITTED CHANGES.
net stop “My Service”
C:WindowsMicrosoft.NETFramework64v4.0.30319installutil /u MyService.exe
git stash save –keep-index –include-untracked
git pull
C:WindowsMicrosoft.NETFramework64v4.0.30319installutil MyService.exe
SC failure “My Service” actions=restart/60000/restart/60000/restart/60000 reset=86400
net start “My Service”

The SC command may not be applicable to you, but this tells the service to restart in the event of a failure.

Hope this helps someone!

Flatlogic Admin Templates banner

Leave a Reply

Your email address will not be published. Required fields are marked *