c# - System.Security.SecurityException : The source was not found, 但无法搜索部分或所有事件日志。无法访问的日志:安全

标签 c# .net windows windows-services event-log

我正在尝试创建一个 Windows 服务,但是当我尝试安装它时,它回滚给我这个错误:

System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.

我不知道这意味着什么 - 我的应用程序只有最低限度,因为我只是先测试一下。

我的安装程序代码:

namespace WindowsService1
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            //set the privileges
            processInstaller.Account = ServiceAccount.LocalSystem;
            processInstaller.Username = null;
            processInstaller.Password = null;

            serviceInstaller.DisplayName = "My Service";
            serviceInstaller.StartType = ServiceStartMode.Manual;

            //must be the same as what was set in Program's constructor
            serviceInstaller.ServiceName = "My Service";

            this.Installers.Add(processInstaller);
            this.Installers.Add(serviceInstaller);
        }

        private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {
        }

        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {
        }
    }
}

我的服务代码:

public partial class Service1 : ServiceBase
{
    public Service1()
    {
        this.ServiceName = "My Service";
    }

    protected override void OnStart(string[] args)
    {
        base.OnStart(args);
    }

    protected override void OnStop()
    {
        base.OnStop();
    }
}

最佳答案

我在使用 installutil 时尝试从命令行安装服务时遇到了同样的异常在 Windows 7 中。解决方案是以管理员身份打开命令行,然后运行 ​​installutil。

此外,您可能会发现使用像 TopShelf 这样的框架更容易。托管您的服务,因为它管理所有 setup configuration从服务的名称和描述到恢复过程的工作方式。它还允许在调试时从 IDE 内部轻松启动服务。

关于c# - System.Security.SecurityException : The source was not found, 但无法搜索部分或所有事件日志。无法访问的日志:安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5822310/

相关文章:

.net - 如何将包含日期的字符串转换为不同的格式?

c# - 如何使用 Devexpress 获取已在 C#.Net 中创建的模板/报告?

c# - 在自定义控件上实现 AutoSize 的最佳做法是什么?

c# - 每次打开应用程序窗口(其他进程)时如何执行一些代码?

windows - GDI GradientFill 不适用于屏幕外位图

c# - 无法将类型为 'system.data.datatable' 的对象转换为类型

c# - 在 Entity Framework 中添加具有多对多关系的项目

c++ - 确定由 Windows GUI 操作触发的基础调用

c# - 您能否将匿名对象作为 json 发布到 web api 方法,并将 json 对象的属性与 webapi 调用的参数相匹配?

c# - WPF Helix如何在代码中使用 "zoom extent"viewport3d?