posted by Will Senn on Mon 5th Jan 2004 19:35 UTC

"Windows .NET Services, Page 5"

8. Build the Service

Building the service is a breeze.

From the IDE's main menu, select Build - Build Solution.


If the build succeeded, you will see the line below in the Output window:
Build: 1 succeeded, 0 failed, 0 skipped
If it fails to build it's probably a typing error or a missed step. Retrace your steps and verify that you haven't missed anything. If all else fails, email me and I might be able to help.

That's it, now let's install the service.


9. Install the Service

This is one of the steps that requires the Visual Studio .NET 2003 Command Prompt. If you have not already started it, start it now and change to the project directory (directory where the exe file was written). You can determine this in the IDE by selecting from the main menu - Project - Properties (timedService must be selected in the Solution Explorer) and looking at the Project - Project Folder field (hover over it for a tooltip or click it to select for pasting into a cd command). If you copy it from there you will need to cd into bin\debug to get to the actual exe.



a. Verify that you are in the correct directory by typing dir, you should see the file timedService.exe in the directory.
b. Type installutil.exe timedService.exe to install the service.
If the install is successful, you will see these two lines:
	The Commit phase completed successfully.
	The transacted install has completed.
Otherwise look at the output, and the files - timedservice.InstallLog and timedservice.InstallState that will have been created, to determine the cause, and retry after correcting the problem.


10. Run the Service

Running the service is what it's all about.

a. In windows Click Start-Settings-Control Panel.
b. Double click on the Administrative Tools icon.
c. Double click on the Services icon.
d. Click on the timedService entry
e. Click on the Play button (right triangle) at the top of the Services window.
The service should now be running and the Status field should say Started.



To verify that the service is doing what it should, browse to the log.txt file and open it in your favorite text editor. Scroll to the bottom of the file and you will see an entry like this:
	[1/2/2004 10:02:00 AM]: I am ALIVE!
Wait a while (more than 30 seconds) and you will see more entries with timestamps 30 seconds apart - you may need to refresh your editor to see the changes.




11. Stop the Service

What goes up, must come down.

a. In windows Click Start-Settings-Control Panel.
b. Double click on the Administrative Tools icon.
c. Double click on the Services icon.
d. Click on the timedService entry
e. Click on the Stop button (square) at the top of the Services window.
The service should now be stopped and the Status field should be empty.



12. Uninstall the Service

While I would like to think that you have found this Service to be the Killer App of all time, I will go ahead and tell you how to uninstall the service. You will need this knowledge in order to be able to develop .NET Services.

This step requires the Visual Studio .NET 2003 Command Prompt. Start it now and change to the project directory (directory where the exe file was written). You will need to cd into bin\debug to get to the actual exe.

a. Close the Services application if it is running.
b. Verify that you are in the correct directory by typing dir, you should see the file timedService.exe in the directory.
c. Type installutil.exe /u timedService.exe to uninstall the service.
If the uninstall is successful, you will see this line:
	The uninstall has completed.
Otherwise look at the output to determine the cause and retry after correcting the problem.


Conclusion The usual development cycle of edit, compile, debug, edit and recompile is applicable with service as well, with two additions:

edit, compile, install, debug, uninstall, edit, recompile, reinstall.
The uninstall and reinstall steps are really only necessary when you make changes that impact either of the Service Installer Objects - timedServiceProcessInstaller or timedServiceInstaller.

I hope that you have found this guide instructive and helpful. I sure could have used it the other day. My wife would have appreciated it. Let me know if there are errors or omissions and I will try to update the guide.

Resources Here are some good places to look for more information

a. F1 and Shift-F1 - no, really! It's not the best, but it should be your first line of defense.
b. Google is where you will have the most luck.
c. Got Dot Net is a pretty decent place to visit.
d. Code Project has a lot of source code for .NET.
e. Code Guru has a lot of .NET related material.
f. Microsoft MSDN .NET Framework Home Page - If all else fails, use the source...
g. Download the source
h. Email the author Will Senn.
Table of contents
  1. "Windows .NET Services, Page 1"
  2. "Windows .NET Services, Page 2"
  3. "Windows .NET Services, Page 3"
  4. "Windows .NET Services, Page 4"
  5. "Windows .NET Services, Page 5"
e p (0)    31 Comment(s)