windows service... when do we need installer

S

sidd

Hi All,
i have some doubts on .net windows services..
please see if some one could help me understand this..

1)is it possible to install a windows service which does not have a
installer added to it,
using installutil.exe

OR
is it must to have an installer to the service project to be able to
install it using installutil.exe

2)why exactly do you have to add installer to a
..net windows service project .
some of the samples i saw were for creating a custom event log ,or for
performance counter ..but it should be possible to do all this even
in the "OnStart" or in the constructor of the windows service.
so when exactly would you need a installer.

thanks
siddharth
 
G

Guy LaRouche

sidd said:
Hi All,
i have some doubts on .net windows services..
please see if some one could help me understand this..

1)is it possible to install a windows service which does not have a
installer added to it,
using installutil.exe

My experience ( I have writen a few windows services so far ) is that it
needs the installer. I have seen some articles ( in c-sharpfriends, for
example ) where they don't mention the installer. But in the MS
documentation for creating a web service, they say to add the installer.

It's very simple to do anyway and it adds a lot of properties, such as start
automatically, or manually , so why not do it.
OR
is it must to have an installer to the service project to be able to
install it using installutil.exe

2)why exactly do you have to add installer to a
.net windows service project .
some of the samples i saw were for creating a custom event log ,or for
performance counter ..but it should be possible to do all this even
in the "OnStart" or in the constructor of the windows service.
so when exactly would you need a installer.

The installer seems to be the 'hook' for allowing the OS to install and run
the service.

Other than adding it to allow me to 'install' the service, I have never used
it for anything else. Like you, I put all the tracing and logging and so
on in the service code itself.
 
K

Kevin Yu [MSFT]

Hi siddharth,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know when an installer
class is needed in a windows service application. If there is any
misunderstanding, please feel free to let me know.

As far as I know, if you need to install the windows service to your
computer, the installer class is required. The installutil.exe need to get
information from it to decide properties for that service. For example, a
service's StartType may be set to start the service automatically at reboot
or require a user to start the service manually. Also Install and Uninstall
methods are called during installation and uninstallation. The service
cannot be installed onto the machine without the installer class.

The OnStart or the constructor of the windows service does things when
service starts, while the installer class does things when the service is
being installed.

For more information, please check the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemServiceProcessServiceInstallerClassTopic.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
N

Nick Malik

Hello Sidd,

I've only created two production windows services, and this wasn't a
stumbling block. However, from my experience:

The application needs code, in it, that will run on installation. It does
not need for you to package it as an MSI. You can run the code (the
installer class) by calling installutil.

--- N
 
J

Jay B. Harlow [MVP - Outlook]

Sidd,
In addition to the other comments.

The installer for a Windows Service will install the Windows Service itself,
allowing you to start it in the first place.

I would recommend using Installers for the custom event log & performance
counters, as the account that the service runs under may not be authorized
to create event logs & performance counters.

Also the Windows Service itself has a "default" event log that it may use
before OnStart or your code has a chance to execute.

Hope this helps
Jay
 
M

Michael

I don't think you would need the installer if you want to add all the
proper entries into the registry (under
HKEY_LOCAL_MACHINE\system\currentcontrolset\services). Also, the
system account does have permissions to create
Its own source and log name, in our services we have our own log name
other than the Application logs.
Michael
 
J

Jay B. Harlow [MVP - Outlook]

Michael,
That's the key word, if you want to add the proper entries into the
registry. I question why would I want to add all the proper entries myself,
when the InstallerUtil knows what they are by virtue of using reflection to
call the System.ServiceProcess.ServiceProcessInstaller class.

The Service itself cannot do it, as it can't run as a Service without them
(chicken & egg problem).

You're assuming the Service is running under the system account, Services do
not have to run under the service account!

Otherwise you are correct.

If you really don't want to use InstallUtil.exe, I would create my own
InstallUtil that did the same thing, use reflection to find all the
Installer attributes, creating an instance of them and invoking the
methods...

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top