Windows Service installation problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mika M

    Windows Service installation problem

    I'm programming quite simple Windows Service using C# 2005. I also made
    setup for it into same solution.

    When I run setup to install service, it's going fine into C:\Program
    Files\MyCompany \My Service, and Event Log tells...

    Event Type: Information
    Event Source: MsiInstaller
    Event Category: None
    Event ID: 11707
    Date: 11.6.2008
    Time: 10:37:28
    User: ...\...
    Computer: MYCOMPUTER
    Description:
    Product: My Service -- Installation completed successfully.

    For more information, see Help and Support Center at
    http://go.microsoft.com/fwlink/events.asp.

    ....but when I check Computer Management/Services, it is not there in
    services list!


    I made earlier another service same way, and it installed that service
    into services list fine (but is not starting the service automatically).
    When I'm comparing these services, I don't find what is wrong with this
    new service intallation.

    Anyway I can install this new service into services list using
    C:\Program Files\MyCompany \My Service\install .bat-file containing...


    @ECHO OFF
    C:\WINDOWS\Micr osoft.NET\Frame work\v2.0.50727 \installutil /i MyService.exe

    NET START MyService
    PAUSE

    and then the Event Log tells...

    Event Type: Information
    Event Source: MyService
    Event Category: None
    Event ID: 0
    Date: 11.6.2008
    Time: 10:54:44
    User: N/A
    Computer: MYCOMPUTER
    Description:
    Service started successfully.

    For more information, see Help and Support Center at
    http://go.microsoft.com/fwlink/events.asp.


    Any succestions what might be wrong with my installation?
  • Claire

    #2
    Re: Windows Service installation problem

    "Mika M" <mika.mahonen_r emovethis@kolum bus.fiwrote in message
    news:OlU2Yk5yIH A.6096@TK2MSFTN GP06.phx.gbl...
    ...but when I check Computer Management/Services, it is not there in
    services list!
    I made earlier another service same way, and it installed that service
    into services list fine (but is not starting the service automatically).
    When I'm comparing these services, I don't find what is wrong with this
    new service intallation.
    1) First, did you add a project installer to your service?
    To do this in VS2005, have service1.cs (or whatever your service1.cs file
    was renamed as) open in the design mode window. Right click on it and select
    "Add Installer" from the context menu. This 2nd installer installs your
    service into windows services when the main application setup is run.
    Doing this causes file ProjectInstalle r.cs file to be added to the project.
    Double click that in solution explorer to show design window (if it's not
    already open) and you'll see a blank page with 2 embedded controls,
    serviceProcessI nstaller1 and serviceInstalle r1.
    Set the properties for serviceInstalle r1 and serviceProcessI nstaller1 as you
    like. (I have serviceProcessI nstaller1.Accou nt set to LocalMachine for
    accessing my database and serviceInstalle r1.ServiceName set to
    myservice.servi ce, set serviceInstalle r1.Description to some useful text to
    describe your service)
    That should be enough to get your service installed in windows services.

    2) To make run your service after installation...
    Open the file "ProjectInstall er.cs" in design view. Select the "background "
    in the designer window (not the embedded controls) and switch to the events
    section of the property editor. Double click the "Committed" event to
    generate an event handler in the code.
    The following code works on my installation

    private void ProjectInstalle r_Committed(obj ect sender, InstallEventArg s
    e)
    {
    try
    {
    // Change the following to your service name. Should be
    serviceInstalle r1.ServiceName
    string servicename = "myservice.serv ice";
    System.ServiceP rocess.ServiceC ontroller[] services;
    services = System.ServiceP rocess.ServiceC ontroller.GetSe rvices();
    bool Found = false;
    foreach (ServiceControl ler sc in services)
    if (string.Compare (servicename, sc.ServiceName, true) == 0)
    Found = true;
    if (Found)
    {
    ServiceControll er Controller = new ServiceControll er(servicename) ;
    if (Controller.Sta tus == ServiceControll erStatus.Stoppe d)
    Controller.Star t();
    }
    }
    catch
    {

    }
    }


    Comment

    • Mika M

      #3
      Re: Windows Service installation problem

      Thanks for the reply!

      My setup project was only missing "Custom Actions". That was why it
      didn't install my application into services list. I noticed it by myself
      at last.

      That is good to know how to start service after installation! I'll try
      it on monday.
      --

      Claire kirjoitti:
      "Mika M" <mika.mahonen_r emovethis@kolum bus.fiwrote in message
      news:OlU2Yk5yIH A.6096@TK2MSFTN GP06.phx.gbl...
      >...but when I check Computer Management/Services, it is not there in
      >services list!
      >I made earlier another service same way, and it installed that service
      >into services list fine (but is not starting the service
      >automatically) . When I'm comparing these services, I don't find what
      >is wrong with this new service intallation.
      >
      1) First, did you add a project installer to your service?
      To do this in VS2005, have service1.cs (or whatever your service1.cs
      file was renamed as) open in the design mode window. Right click on it
      and select "Add Installer" from the context menu. This 2nd installer
      installs your service into windows services when the main application
      setup is run.
      Doing this causes file ProjectInstalle r.cs file to be added to the
      project. Double click that in solution explorer to show design window
      (if it's not already open) and you'll see a blank page with 2 embedded
      controls, serviceProcessI nstaller1 and serviceInstalle r1.
      Set the properties for serviceInstalle r1 and serviceProcessI nstaller1 as
      you like. (I have serviceProcessI nstaller1.Accou nt set to LocalMachine
      for accessing my database and serviceInstalle r1.ServiceName set to
      myservice.servi ce, set serviceInstalle r1.Description to some useful text
      to describe your service)
      That should be enough to get your service installed in windows services.
      >
      2) To make run your service after installation...
      Open the file "ProjectInstall er.cs" in design view. Select the
      "background " in the designer window (not the embedded controls) and
      switch to the events section of the property editor. Double click the
      "Committed" event to generate an event handler in the code.
      The following code works on my installation
      >
      private void ProjectInstalle r_Committed(obj ect sender,
      InstallEventArg s e)
      {
      try
      {
      // Change the following to your service name. Should be
      serviceInstalle r1.ServiceName
      string servicename = "myservice.serv ice";
      System.ServiceP rocess.ServiceC ontroller[] services;
      services = System.ServiceP rocess.ServiceC ontroller.GetSe rvices();
      bool Found = false;
      foreach (ServiceControl ler sc in services)
      if (string.Compare (servicename, sc.ServiceName, true) == 0)
      Found = true;
      if (Found)
      {
      ServiceControll er Controller = new ServiceControll er(servicename) ;
      if (Controller.Sta tus == ServiceControll erStatus.Stoppe d)
      Controller.Star t();
      }
      }
      catch
      {
      >
      }
      }
      >
      >

      Comment

      • Arthur Z

        #4
        Windows Service installation problem

        In my case the correct event to start the service upon installation was ProjectInstalle r_AfterInstall.
        The event ProjectInstalle r_Committed did not start the service.

        Comment

        Working...