4

I currently have a program to install correctly as a service but the Startup Type is set to "Manual". How do I make this application set Startup Type = Automatic?

static void Main(string[] args) {

        if (System.Environment.UserInteractive) {

            if (args.Length > 0) {
                switch (args[0]) {
                    case "/install": {
                        ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                        break;
                    }
                    case "/uninstall": {
                        ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                     break;
                 }
             }
         }
     } else {
         if (!Environment.UserInteractive) {
             // running as service
             using (var service = new DocLogicJMS())
                 ServiceBase.Run(service);
         } else {
             // running as console app
             Start(args);
             Console.WriteLine("Press any key to stop...");
             Console.ReadKey(true);
             Stop();
         }
     }
}

And JMS is:

namespace JMS {
partial class DocLogicJMS {
    /// <summary> 
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing) {
        if (disposing && (components != null)) {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #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.ServiceName = "DocLogic JMS";
    }

    #endregion
}

}

Sari Rahal
  • 1,897
  • 2
  • 32
  • 53

1 Answers1

0

It seems this question has been answered here already: How do I change a Windows Service's startup type in .NET (post-install)?

This seems to be the most upvoted answer:

var svc = new ServiceController("ServiceNameGoesHere");  
ServiceHelper.ChangeStartMode(svc, ServiceStartMode.Automatic); 
Community
  • 1
  • 1
Mark Atkinson
  • 458
  • 8
  • 14
  • I have added more information about my issue. I think this is close to what I need but not exactly. – Sari Rahal Oct 11 '16 at 17:50
  • But you did put me on the right track. Thank you. I needed these to lines: this.JMSserviceInstaller.StartType = ServiceStartMode.Automatic; this.JMSserviceInstaller.DelayedAutoStart = false; – Sari Rahal Oct 11 '16 at 18:16