【发布时间】:2013-02-14 17:32:09
【问题描述】:
我需要安装一个可执行文件作为服务,我需要使用用 C# 编写的 PowerShell cdmlet 来完成。本质上,我需要创建所需的注册表项等来定义服务(包括要运行的可执行文件 - 一种 srvany.exe)。
我还需要能够定义此服务的登录身份(凭据)。
TIA,汉斯
到目前为止我尝试了什么。我一直在研究 ServiceProcessInstaller 和 ServiceProcessInstaller 类,但它们错过了定义“外部”可执行文件的可能性。
public partial class MyServiceInstaller : Installer
{
public MyServiceInstaller()
{
IDictionary saveState = null;
this.Installers.Clear();
ServiceProcessInstaller spi = new ServiceProcessInstaller();
ServiceInstaller si = new ServiceInstaller();
spi.Account = ServiceAccount.LocalSystem;
spi.Username = null;
spi.Password = null;
si.ServiceName = "MyService";
si.DisplayName = "MyService";
si.StartType = ServiceStartMode.Automatic;
si.Description = "MyService - I wish....";
spi.Installers.Add(si);
this.Installers.Add(spi);
this.Install(saveState);
}
}
因为找不到添加可执行路径(服务映像路径)的方法,所以卡在这里
【问题讨论】:
-
还有
what have you tried?您在编写代码时遇到了哪些特殊困难?我在你的问题中只能看到I need to ...,但我在任何地方都没有看到here's the code I tried but ...
标签: c# powershell service windows-services