【发布时间】:2015-06-12 06:52:22
【问题描述】:
我有 this 代码来从代码安装 Windows 服务。
ServiceProcessInstaller ProcesServiceInstaller = new ServiceProcessInstaller();
ProcesServiceInstaller.Account = ServiceAccount.LocalSystem;
//ProcesServiceInstaller.Username = "";
//ProcesServiceInstaller.Password = "";
ServiceInstaller ServiceInstallerObj = new ServiceInstaller();
InstallContext Context = new System.Configuration.Install.InstallContext();
String path = String.Format("/assemblypath={0}", @"C:\Users\g\Documents\Visual Studio 2012\Projects\WindowsService1Test\WindowsService1Test\bin\Debug");
String[] cmdline = { path };
Context = new System.Configuration.Install.InstallContext("", cmdline);
ServiceInstallerObj.Context = Context;
ServiceInstallerObj.DisplayName = "MyService Display name2";
ServiceInstallerObj.Description = "MyService installer test";
ServiceInstallerObj.ServiceName = "MyService2";
ServiceInstallerObj.StartType = ServiceStartMode.Automatic;
ServiceInstallerObj.Parent = ProcesServiceInstaller;
System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
ServiceInstallerObj.Install(state);
问题是它有效。但是当我尝试运行该服务时,我得到了这个消息框(错误 5:访问被拒绝):
如果有人可以帮助我,我将不胜感激,因为我对此感到困惑
【问题讨论】:
标签: c# windows windows-services