我正在尝试创建一个 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/