【问题标题】:Install TopShelf service from C# Application从 C# 应用程序安装 TopShelf 服务
【发布时间】:2016-01-07 10:22:49
【问题描述】:

您好,我正在尝试在 c# 中从 Windows 窗体应用程序安装服务(使用 TopShelf 创建)。 我正在考虑使用服务管理器类,但这似乎不是一个选择。因此,我正在考虑使用 Process 类来调用安装。 通常要安装 Topshelf 服务,您需要运行以下命令:

MyService.EXE 安装 -someOptions

但是当我在进程中尝试这个时

 var servicePath = @"C:\Program Files (x86)\Blah Services\bin\Gateway\Gateway.exe";
 var userName = "test";
 var password = "Word!";
 
 try{
      Process proc = new Process(); //call new Process
        ProcessStartInfo info = new ProcessStartInfo(); //call new ProcessStartInfo
        info.Arguments = "install -instance:default -username:" + userName + "-password:" + password;
        info.FileName = servicePath; //set the file name (location)

        proc.StartInfo = info; //put the StartInfo into the Procces method
        proc.Start(); //Start the procces (sc.exe with the arguments)
        proc.WaitForExit(); //waits till the procces is don
     
   }

我什至考虑过使用命令窗口并将参数和文件名替换为以下内容:

   info.Arguments = "//k " + servicePath +" install -instance:default -username:" + userName + "-password:" + password;
            info.FileName = "cmd.exe"; //set the file name (location)

但似乎都没有工作。有人有什么想法吗?

【问题讨论】:

    标签: c# windows-services topshelf


    【解决方案1】:

    只是尝试一下,但您是以管理员身份运行 WinForms 应用程序(或 Visual Studio)吗?作为管理员,我一直在使用以下工具来启动 TopShelf 安装:

    System.Diagnostics.Process.Start(@"C:\winServices\extracts\bin\service.exe", "install");
    

    【讨论】:

      猜你喜欢
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多