Web Log of Aleksey Nudelman: Thoughts on Software Architecture

Analysis and Review of Microsoft Technologies for IT Managers, Architects and Developers

Home » Archives » August 2004 » C# Tutorial, Lesson 22: Writing and Installing Windows Services

[Previous entry: "Interview with Andrew Troelsen"] [Next entry: "Windows Forms class at UCLA Extension"]

08/10/2004: "C# Tutorial, Lesson 22: Writing and Installing Windows Services"


I have finally finished 22nd lesson in the tutorial www.csharpcomputing.com/Tutorials/Lesson22.htm". Check it out...

Replies: 2 Comments

on Monday, September 6th, Aleksey Nudelman said

Wow! I didn't know you can debug a service with Debugger.Launch(). I will definitely try it out!

on Sunday, August 29th, Dawn Strickrott said

Hi Aleksey,

I checked out the Windows Service tutorial and thought I'd share a few things I've learned from my experiences writing and installing them.

After adding the installer to the project, enter the name you want to appear in the Service Control Manager in the DisplayName field. Tip: to keep names consistent, I enter the same name in the
ServiceName field and the DisplayName field. This will ensure the name that gets
displayed in the SCM is the same name as your service name. The SCM displays what's entered in the DisplayName field so it may as well be the name of the service.
If the DisplayName field is empty, the SCM displays the value in the ServiceName field.

I used installutil to install the service on the target machine. To install the Windows Service on a machine with the .NET SDK, open a .NET command prompt, and enter installutil /i
fullfilepathtoservice.exe. The service can be removed from the machine with the command installutil /u fullfilepathtoservice.exe.

If the target machine has the .NET Framework installed but not the .NET SDK, open a
regular command prompt and type C:\WINNT\Microsoft.NET\Framework\v1.1.4322 installutil /i fullfilepathtoservice.exe.

To debug the service, add this line of C# code -
Debugger.Launch();
to the OnStart() method, build the solution, and install the service.
If the StartType is manual, open the SCM and start the service. The service must be installed
and running to be able to step into it. This may seem obvious but it isn't if it's the first service you've ever written. When the
debugger line of code is reached, the program will launch a tool that asks you to select the debugger
(I usually choose the current instance of VS.NET) and choose the
program type to debug. The default selections are CLR and Native; I usually uncheck Native.

Keep the interesting interviews coming!

Regards,
Dawn

  Home
  Archives
Phishing Inspector is  available

Copyright© 2006 Aleksey Nudelman