Microsoft.NET

……………………………………………….Expertise in .NET Technologies

Important Questions on Windows Services

Posted by Ravi Varma Thumati on October 6, 2009

Read these questions and think of possible answers. Compare your thoughts with the answers given in the “Answers” section.

Questions

1.     Can we debug windows service without installing it on the computer?

2.     Can we debug the OnStart method of windows service?

3.     Is there any alternative for windows service application?

4.     How to start, pause, continue and stop the service using command line?

5.     How to set permissions on windows service?

6.     Can we share the process among multiple windows services?

7.     Is there way to create installer other than by using Setup project template of Visual Studio?

Answers

1.  No, we cannot debug windows service without installing and starting it. However, we can debug the functional part by creating separate assemblies using console or windows application and then use the debugged assembly in windows service project. This is not possible in all cases, especially when we need to debug run time issues.

2.  As the service must be started to attach its process to debugger, we need the service to be started in advance. Hence, normally we cannot debug the OnStart method of service.

However, we can make an extra dummy windows service which should internally start the actual service. By attaching debugger to the process of dummy service we can step into the OnStart method of actual service to debug it.

3. Probably, we can use Windows Operating System’s Schedule Tasks as an alternative of windows service. We can implement required functionalities in a valid program and then configure it with Schedule Tasks.

4.  To start, pause, continue and stop the service through command line use net start ServiceName, net pause ServiceName, net continue ServiceName and net stop ServiceName, respectively.

5.  Permissions for windows service depend upon the account type (Local Service/Network Service/Local System/User) set for the service. If service is set to use particular user account then permissions set for specified user becomes the permission for the service.

6.  Yes, windows services could be implemented like other exe applications if they do not need GUI. One major difference is that windows service is managed by SCM (Service Control Manager) which provides options to implement many settings and events. Internally the Main method of the service application issues the Run command and then Run method loads the service in SCM.

7.  We can create installer using command-line utility Installutil.exe by passing the path of service’s executables.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: