System.Security.SecurityException:未找到源,但无法搜索某些或所有事件日志。(System.Security.SecurityException: The source

编程入门 行业动态 更新时间:2024-10-19 21:31:12
System.Security.SecurityException:未找到源,但无法搜索某些或所有事件日志。(System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security)

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

System.Security.SecurityException:未找到源,但无法搜索某些或所有事件日志。 无法访问的日志:安全。

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

我的安装员代码:

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(); } }

I am trying to create a Windows Service, but when I try and install it, it rolls back giving me this error:

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

I don't know what this means - my application has the bare minimum since I am just testing things out first.

My Installer Code:

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) { } } }

My Service Code:

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(); } }

最满意答案

如果您被提示输入用户名和密码,那么某处设置为Account = ServiceAccount.User - 这是唯一可以(应该)发生的方式。 也许您上面的注释中的代码未被执行,或者后来执行代码被更改。

至于你的第二段,一般来说,如果你不希望在控制台上看到一个服务,或者作为一个任务运行,我会认为一个服务会很好。 我不知道我是否理解有关运行它作为ASP.NET的部分,并且不允许您看到数据库...

最后,在最后一段中,我不能在不了解安装程序代码中发生了什么的情况下与NullExeception进行通话。

If you are being prompted for a user name and password, then something, somewhere is set to Account = ServiceAccount.User - that's the only way that could (should) happen. Perhaps your code in the comment above is not being executed or it is being changed back by later executing code.

As far as your second paragraph, in general, I would think a service would be fine for this if you don't want it to be see on the console or run as a task. I am not sure if I understand the part about running it as ASP.NET and having it not allow you to see the database...

Finally, in your last paragraph, I can't speak to the NullExeception without knowing more about what is going on in your installer's code.

更多推荐

本文发布于:2023-07-31 01:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340504.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未找到   事件   日志   SecurityException   System

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!