我正在尝试基于this walkthrough创建一个简单的Windows服务。当我尝试执行命令时:
C:\worl\Project Alpha\Code\AlphaBackendService\AlphaBackendService\bin\Debug>ins
tallutil.exe AlphaBackendService.exe
它会显示一个包含用户名,密码,确认密码的对话框。我没有输入任何内容,安装失败。它想要什么帐户?为什么我不能只使用我输入的任何内容?这是因为EventLog需要许可:
public partial class AlphaBackendService : ServiceBase
{
public AlphaBackendService()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("AlphaSource"))
{
System.Diagnostics.EventLog.CreateEventSource("AlphaSource", "AlphaLog");
}
eventLog1.Source = "AlphaSource";
eventLog1.Log = "AlphaLog";
}
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
}
protected override void OnStop()
{
eventLog1.WriteEntry("In OnStop");
}
}
答案 0 :(得分:20)
在Project Installer中,将属性Account设置为Local System(来自设计器)或在InitializeComponent()方法中设置以下代码
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;