HOW TO REGISTER A .net WINDOWS SERVICE? 
Author Message
 HOW TO REGISTER A .net WINDOWS SERVICE?

Hi All,

How to register a .net Windows Service?
I tried
installutil myservice.exe
but, the service doesn't get listed in the list of services.

TIA,
NumLock



Tue, 22 Mar 2005 17:27:50 GMT  
 HOW TO REGISTER A .net WINDOWS SERVICE?
You need to add the installer class for your service.  Assuming you are
using VS.Net you need to do the following (if not see later on):

1. make sure you are in design view for your service.

2. click somewhere on the background of the service itself not any
components you've added ( like selecting the form in a form based app).

3. In the properties window you will see a link saying "Add installer" in
the bottom right.  Click this

4. the wizard will create the component class containing 2 installers, 1 for
the service and one for the service's associated process.

5. Go to design view in the porjectinstaller class and select
ServiceInsatller1

6.    In the properties window set the service name as required and set the
starttype if required.

when you run installutil with your built service now you should get prompted
to enter user details for the service.

If you don't have VS.Net the class you need to add looks as follows:

'=========VB Code block --START=======================================

Imports System.ComponentModel
Imports System.Configuration.Install

<RunInstaller(True)> Public Class ProjectInstaller
    Inherits System.Configuration.Install.Installer

#Region " Component Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Installer overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    Friend WithEvents ServiceProcessInstaller1 As
System.ServiceProcess.ServiceProcessInstaller
    Friend WithEvents ServiceInstaller1 As
System.ServiceProcess.ServiceInstaller
    <System.Diagnostics.De{*filter*}StepThrough()> Private Sub
InitializeComponent()
        Me.ServiceProcessInstaller1 = New
System.ServiceProcess.ServiceProcessInstaller()
        Me.ServiceInstaller1 = New System.ServiceProcess.ServiceInstaller()
        '
        'ServiceProcessInstaller1
        '
        '*******SET USERNAME AND PASSWORD HERE IF YOU WANT TO HARDCODE IT**
        '*******INSTALLUTIL WILL PROMPT FOR THIS INFO IF YOU LEAVE AS IS
****
        Me.ServiceProcessInstaller1.Password = Nothing
        Me.ServiceProcessInstaller1.Username = Nothing
        '
        'ServiceInstaller1
        '
        '*******IMPORTANT - SET YOUR SERVICE NAME HERE!*************
        Me.ServiceInstaller1.ServiceName = "MyService"
        Me.ServiceInstaller1.StartType =
System.ServiceProcess.ServiceStartMode.Automatic
        '
        'ProjectInstaller
        '
        Me.Installers.AddRange(New System.Configuration.Install.Installer()
{Me.ServiceProcessInstaller1, Me.ServiceInstaller1})

    End Sub

#End Region

End Class

'=========VB Code block --END=======================================

HTH

Mark


Quote:
> Hi All,

> How to register a .net Windows Service?
> I tried
> installutil myservice.exe
> but, the service doesn't get listed in the list of services.

> TIA,
> NumLock



Tue, 22 Mar 2005 19:23:16 GMT  
 HOW TO REGISTER A .net WINDOWS SERVICE?
PS: Sorry for sending the code in VB to a CSharp group, but you get the
idea..

if you can't translate it yourself here it is

//=====C# code block START========================

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

namespace WindowsService1
{
 /// <summary>
 /// Summary description for ProjectInstaller.
 /// </summary>
 [RunInstaller(true)]
 public class ProjectInstaller : System.Configuration.Install.Installer
 {
  private System.ServiceProcess.ServiceProcessInstaller
serviceProcessInstaller1;
  private System.ServiceProcess.ServiceInstaller serviceInstaller1;
  /// <summary>
  /// Required designer variable.
  /// </summary>
  private System.ComponentModel.Container components = null;

  public ProjectInstaller()
  {
   // This call is required by the Designer.
   InitializeComponent();

   // TODO: Add any initialization after the InitComponent call
  }

  #region Component Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   this.serviceProcessInstaller1 = new
System.ServiceProcess.ServiceProcessInstaller();
   this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
   //
   // serviceProcessInstaller1
   //
//*******SET USERNAME AND PASSWORD HERE IF YOU WANT TO HARDCODE IT**
//*******INSTALLUTIL WILL PROMPT FOR THIS INFO IF YOU LEAVE AS IS
   this.serviceProcessInstaller1.Password = null;
   this.serviceProcessInstaller1.Username = null;
   //
   // serviceInstaller1
   //
    //*******IMPORTANT - SET YOUR SERVICE NAME HERE!*************
   this.serviceInstaller1.ServiceName = "Service1";
   //
   // ProjectInstaller
   //
   this.Installers.AddRange(new System.Configuration.Install.Installer[] {
                       this.serviceProcessInstaller1,
                       this.serviceInstaller1});

  }
  #endregion
 }

Quote:
}

//=====C# code block END========================

Quote:
> You need to add the installer class for your service.  Assuming you are
> using VS.Net you need to do the following (if not see later on):

> 1. make sure you are in design view for your service.

> 2. click somewhere on the background of the service itself not any
> components you've added ( like selecting the form in a form based app).

> 3. In the properties window you will see a link saying "Add installer" in
> the bottom right.  Click this

> 4. the wizard will create the component class containing 2 installers, 1
for
> the service and one for the service's associated process.

> 5. Go to design view in the porjectinstaller class and select
> ServiceInsatller1

> 6.    In the properties window set the service name as required and set
the
> starttype if required.

> when you run installutil with your built service now you should get
prompted
> to enter user details for the service.

> If you don't have VS.Net the class you need to add looks as follows:

> '=========VB Code block --START=======================================

> Imports System.ComponentModel
> Imports System.Configuration.Install

> <RunInstaller(True)> Public Class ProjectInstaller
>     Inherits System.Configuration.Install.Installer

> #Region " Component Designer generated code "

>     Public Sub New()
>         MyBase.New()

>         'This call is required by the Component Designer.
>         InitializeComponent()

>         'Add any initialization after the InitializeComponent() call

>     End Sub

>     'Installer overrides dispose to clean up the component list.
>     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
>         If disposing Then
>             If Not (components Is Nothing) Then
>                 components.Dispose()
>             End If
>         End If
>         MyBase.Dispose(disposing)
>     End Sub

>     'Required by the Component Designer
>     Private components As System.ComponentModel.IContainer

>     'NOTE: The following procedure is required by the Component Designer
>     'It can be modified using the Component Designer.
>     'Do not modify it using the code editor.
>     Friend WithEvents ServiceProcessInstaller1 As
> System.ServiceProcess.ServiceProcessInstaller
>     Friend WithEvents ServiceInstaller1 As
> System.ServiceProcess.ServiceInstaller
>     <System.Diagnostics.De{*filter*}StepThrough()> Private Sub
> InitializeComponent()
>         Me.ServiceProcessInstaller1 = New
> System.ServiceProcess.ServiceProcessInstaller()
>         Me.ServiceInstaller1 = New

System.ServiceProcess.ServiceInstaller()

- Show quoted text -

Quote:
>         '
>         'ServiceProcessInstaller1
>         '
>         '*******SET USERNAME AND PASSWORD HERE IF YOU WANT TO HARDCODE
IT**
>         '*******INSTALLUTIL WILL PROMPT FOR THIS INFO IF YOU LEAVE AS IS
> ****
>         Me.ServiceProcessInstaller1.Password = Nothing
>         Me.ServiceProcessInstaller1.Username = Nothing
>         '
>         'ServiceInstaller1
>         '
>         '*******IMPORTANT - SET YOUR SERVICE NAME HERE!*************
>         Me.ServiceInstaller1.ServiceName = "MyService"
>         Me.ServiceInstaller1.StartType =
> System.ServiceProcess.ServiceStartMode.Automatic
>         '
>         'ProjectInstaller
>         '
>         Me.Installers.AddRange(New

System.Configuration.Install.Installer()

- Show quoted text -

Quote:
> {Me.ServiceProcessInstaller1, Me.ServiceInstaller1})

>     End Sub

> #End Region

> End Class

> '=========VB Code block --END=======================================

> HTH

> Mark



> > Hi All,

> > How to register a .net Windows Service?
> > I tried
> > installutil myservice.exe
> > but, the service doesn't get listed in the list of services.

> > TIA,
> > NumLock



Tue, 22 Mar 2005 19:31:46 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Registering Windows Service.....

2. Windows Media Services and .NET - Problem

3. Windows Service & C++.Net

4. Using ADO.NET & Windows Service

5. calling a NET Windows Service

6. ATL component written in VC.NET 2002 won't register on non .NET machine

7. ATL component written in VC.NET 2002 won't register on non .NET machine

8. Basic windows service from wizard - installs but ain't there for a net start

9. Viewing MMX registers in Register window under Developer Studio 97

10. Viewing MMX registers in Register window under Developer Studio 97

11. nt service(windows service)

12. nt service (windows service)

 

 
Powered by phpBB® Forum Software