c# - 无法安装简单 Windows 服务 - 登录?

标签 c# windows-services

我正在尝试基于 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");
        }
 }

enter image description here

最佳答案

在 ProjectInstaller 中,将属性帐户设置为 LocalSystem(来自设计器)或在 InitializeComponent() 方法中设置以下代码

        this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

关于c# - 无法安装简单 Windows 服务 - 登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21609416/

相关文章:

c# - 用于缩短代码的动态图像名称

C# WPF 使按钮在鼠标悬停时随机移动

c# - 最初设置的类声明在内部是否与在构造函数中设置它们相同?

delphi - 如何从 Delphi 中的服务名称/句柄找到进程 ID?

c# - 获取 Windows 服务的完整路径

vb6 - 在vb6中创建一个windows服务

c# - 通过 WPF MVVM 中不断刷新的存储库持久化 EF 更改

c# - Process.Start 很慢

c# - 查找服务设置为哪个帐户 "Log On As"

windows - 是否可以完全在 node.js 中编写 Windows 服务?