我正在尝试创建一个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.
更多推荐
发布评论