Jeff Hughes wrote:
>
> I am trying to create a window service in C#.
> I created a new Windows Service and used the on_start
> to instantiate a dll. I used InstallUtil.exe to register the
> service. here is the log file from the registration. My
> problem is it will not show up in the service manager so I
> can start it. Any clues?
>
> Thanks,
>
>  Jeff Hughes
>

You will need to add some additional code to the service that gets
generated by the wizard.  Just add a new class definition to the top of
the service class file, like this:

        using System.Configuration.Install;

        [RunInstallerAttribute(true)]
        public class ServiceRegister:
System.Configuration.Install.Installer
        {
                private ServiceInstaller serviceInstaller;
                private ServiceProcessInstaller processInstaller;

                public ServiceRegister()
                {
                        // create the service installer
                        serviceInstaller = new ServiceInstaller();

                        serviceInstaller.StartType =
ServiceStartMode.Manual;
                        serviceInstaller.ServiceName = "My Service";
                        serviceInstaller.DisplayName = "My Service";

                        Installers.Add(serviceInstaller);

                        // create the process installer
                        processInstaller = new
ServiceProcessInstaller();

                        processInstaller.Account =
ServiceAccount.LocalSystem;

                        Installers.Add(processInstaller);
                }
        }

This allows you to set up the configuration for the service.
InstallUtil.exe looks for classes marked with the RunInstallerAttribute
set to true.  You need to add a reference to
System.Configuration.Install as well.

More info at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/h
tml/frlrfSystemServiceProcessServiceProcessInstallerClassTopic.asp

Chris Dix
http://www.thoughtpost.com/



You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to