Tuesday, January 11, 2011

Building and Installing Windows Service Visual Studio 2008

You cannot just hit Run and debug your Windows Service.  That would be really cool, but it is not that hard to get it running.
Build and Install service on your pc:
Choose Build in the Menubar above and choose Build NewService.
serviceblank
This will build your executable in the bin\release folder of your project.  If you try to run the program by itself, it will not run and give you an error.  Instead you have to load the service into your computer by using InstallUtil.exe.
You can run InstallUtil.exe from the VisualStudio Command Prompt.
servicecmd
Installing:

InstallUtil “PATH_TO_YOUR_EXE.exe”
Uninstalling:
InstallUtil “PATH_TO_YOUR_EXE.exe” /U
When you run in the command window, you will see alot of text, and at the bottom it should read:
The Commit phase completed successfully.
The transacted install has completed.
Now we have to start the service in Service Manager. -  Right click on My Computer on the Desktop, and choose Manage.

servicemanage
Choose Services and Applications, Services, and New Service:
servicemanager
Right click and Choose Start.
Then Go to EventViewer, Application and you should see a log for service starting, and after 10 seconds you should see your ‘Service Running” log entry
servicelog
Now you have a running Service.  Don’t forget to stop it.  You dont want to fill your Event log up!  We set the service to Automatic in Part 2, so you may want to uninstall using InstallUtil.exe to remove from your system.

No comments:

Post a Comment