2016-10-11 2 views
1

В настоящее время у меня есть программа для правильной установки в качестве службы, но для параметра «Тип запуска» установлено значение «Вручную». Как установить этот набор приложений Startup Type = Automatic?C# Установка службы и установка автоматического запуска при загрузке

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(); 
     } 
    } 
} 

И JMS является:

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 
} 

}

ответ

0

Кажется, этот вопрос был дан ответ здесь уже: How do I change a Windows Service's startup type in .NET (post-install)?

Это, кажется, самый upvoted ответ:

var svc = new ServiceController("ServiceNameGoesHere"); 
ServiceHelper.ChangeStartMode(svc, ServiceStartMode.Automatic); 
+0

Я добавил дополнительную информацию о моей проблеме. Я думаю, что это близко к тому, что мне нужно, но не совсем. –

+0

Но ты поместил меня на правильный путь. Спасибо. Мне нужны были эти строки: this.JMSserviceInstaller.StartType = ServiceStartMode.Automatic; this.JMSserviceInstaller.DelayedAutoStart = false; –

 Смежные вопросы

  • Нет связанных вопросов^_^