Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#安装服务并设置为启动时自动启动_C#_Windows Services_Managedinstallerclass - Fatal编程技术网

C#安装服务并设置为启动时自动启动

C#安装服务并设置为启动时自动启动,c#,windows-services,managedinstallerclass,C#,Windows Services,Managedinstallerclass,我目前有一个程序可以作为服务正确安装,但启动类型设置为“手动”。如何使此应用程序集启动类型=自动 static void Main(string[] args) { if (System.Environment.UserInteractive) { if (args.Length > 0) { switch (args[0]) { case "/install": {

我目前有一个程序可以作为服务正确安装,但启动类型设置为“手动”。如何使此应用程序集启动类型=自动

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
}
名称空间JMS{
部分类DocLogicJMS{
///  
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置){
if(处理和(组件!=null)){
组件。Dispose();
}
基地。处置(处置);
}
#区域组件设计器生成的代码
///  
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent(){
this.ServiceName=“DocLogic JMS”;
}
#端区
}

}这个问题似乎已经在这里得到了回答:

这似乎是投票最多的答案:

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

这个问题似乎已经在这里得到了回答:

这似乎是投票最多的答案:

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

我已经添加了有关我的问题的更多信息。我认为这接近我需要的,但不完全是。但你确实让我走上了正确的道路。非常感谢。我需要这些代码行:this.JMSserviceInstaller.StartType=ServiceStartMode.Automatic;this.JMSserviceInstaller.DelayedAutoStart=false;我已经添加了有关我的问题的更多信息。我认为这接近我需要的,但不完全是。但你确实让我走上了正确的道路。非常感谢。我需要这些代码行:this.JMSserviceInstaller.StartType=ServiceStartMode.Automatic;this.JMSserviceInstaller.DelayedAutoStart=false;