【发布时间】: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