none
PRB VS2010 - Installer Project (MSI) for Windows Service. SVC removed after install. RRS feed

  • Question

  • PRB VS2010 - Installer Project (MSI) for Windows Service. SVC removed after install.

    Please help,

    I have a VS2010 Installer Project, that installs a windows service. The MSI appears to work, and I have made it start the service after the

    Commit. I have my ProjectInstaller class set the windows service as auto-start, and with a network account.

    After the install, one can see the network account assigned to the service, and it is running.
    But its state is DISABLED. and the moment one stops the service from SCM, it disappears.

    The complete "HKLM\SYSTEM\CurrentControlSet\Services\MyService" registry is GONE.
    How can this happen?

    Almost needless to say, the unistall FAILS, because the service no longer exists.

     


    Here is my code...
    =======================================
    using Microsoft.Win32;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Configuration.Install;
    using System.Diagnostics;
    using System.IO;
    using System.Security.Principal;
    using System.ServiceProcess;
    using System.Windows;
    using System.Windows.Forms;

    namespace HealthPort
    {
      [RunInstaller(true)]
      public partial class ProjectInstaller : Installer
      {
        public System.ServiceProcess.ServiceProcessInstaller ServiceProcessInstaller_MySvc;
        public System.ServiceProcess.ServiceInstaller ServiceInstaller_MySvc;

        public ProjectInstaller()
        {
          ServiceProcessInstaller_MySvc = new System.ServiceProcess.ServiceProcessInstaller();
          ServiceInstaller_MySvc = new System.ServiceProcess.ServiceInstaller();

          ServiceInstaller_MySvc.Description = "MySvc";
          ServiceInstaller_MySvc.DisplayName = "MySvc";
          ServiceInstaller_MySvc.ServiceName = "MySvc";
          ServiceInstaller_MySvc.StartType = System.ServiceProcess.ServiceStartMode.Automatic;

          ServiceProcessInstaller_MySvc.Username = null;
          ServiceProcessInstaller_MySvc.Password = null;
          ServiceProcessInstaller_MySvc.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

          Installers.Add(ServiceProcessInstaller_MySvc);
          Installers.Add(ServiceInstaller_MySvc);
        }

        public override void Install(System.Collections.IDictionary IDictionary_SavedState)
        {
          string
            csTemp,
            ERR = "",
            LA = "";

          string
            csMYSVC_CONF_PWD,
            csMYSVC_DOMAIN,
            csMYSVC_UID,
            csMYSVC_PWD;

          try
          {
            LA = "validate logon credentials";
            csMYSVC_DOMAIN = "MYDOMAN";
            csMYSVC_UID = "MYUID";
            csMYSVC_PWD = "MYPWD";

            ServiceProcessInstaller_MySvc.Username = String.Format
            (
              "{0}\\{1}",
              csMYSVC_DOMAIN,
              csMYSVC_UID
            );
            ServiceProcessInstaller_MySvc.Password = csMYSVC_PWD;
            ServiceProcessInstaller_MySvc.Account = System.ServiceProcess.ServiceAccount.User;

            LA = "process base-handling";
            base.Install(IDictionary_SavedState);
          }
          catch (Exception e)
          {
            ERR = e.Message;
            csTemp = String.Format
            (
              "Error! In an attempt to {0}, the following error occurred:\r\n{1}.",
              LA,
              ERR
            );

            throw new InstallException(csTemp);
          }
        }

        public override void Commit(System.Collections.IDictionary IDictionary_SavedState)
        {
          base.Commit(IDictionary_SavedState);
          ServiceController ServiceController_Temp = null;

          try
          {
            ServiceController_Temp = new ServiceController(ServiceInstaller_MySvc.ServiceName);

            if
            (
              (ServiceController_Temp.Status == ServiceControllerStatus.Stopped)
              ||
              (ServiceController_Temp.Status == ServiceControllerStatus.StopPending)
            )
            {
              ServiceController_Temp.Start();
            }
          }
          catch (Exception)
          {
          }
          finally
          {
            if (!ML.IsNull(ServiceController_Temp))
            {
              ServiceController_Temp.Close();
              ServiceController_Temp = null;
            }
          }
        }
      }
    }

    Tuesday, October 4, 2011 9:44 PM

Answers

  • I figured it out. The code is correct.

    I had to manually go through the registry, and remove all reg keys related tyo MySvc.

    Then I had to make a new version build for all things in the solution, including a new file name for the MSI which I always make to match the solution's current version. Then I re-ran the MSI and it all worked. It appears, once a MSI get broken, this problem will occur, weher it some how keeps re-invoking an older version of the MSI.

     

    • Proposed as answer by pvdg42 Tuesday, October 4, 2011 10:17 PM
    • Marked as answer by Alexander Sun Friday, October 7, 2011 4:07 AM
    Tuesday, October 4, 2011 10:15 PM

All replies

  • I figured it out. The code is correct.

    I had to manually go through the registry, and remove all reg keys related tyo MySvc.

    Then I had to make a new version build for all things in the solution, including a new file name for the MSI which I always make to match the solution's current version. Then I re-ran the MSI and it all worked. It appears, once a MSI get broken, this problem will occur, weher it some how keeps re-invoking an older version of the MSI.

     

    • Proposed as answer by pvdg42 Tuesday, October 4, 2011 10:17 PM
    • Marked as answer by Alexander Sun Friday, October 7, 2011 4:07 AM
    Tuesday, October 4, 2011 10:15 PM
  • It's really good thing to use virtual machines for install testing.
    Phil Wilson
    Wednesday, October 5, 2011 4:52 PM