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(); } }
In the Group Policy editor, expand Windows Setting, expand Security Settings, expand Local Policies, and then expand Security Options. Double-click Event log: Application log SDDL, type the SDDL string that you want for the log security, and then select OK.
To create an event source, you need to have a name for your new source (called the Event Source Name) and the name of the log where the event source will be a part. If the event log entries would be written to the standard “Application”, “System” or “Security” logs, then you can use that as the name of the log.
The WriteEntry method writes the given string directly to the event log; it does not use a localizable message resource file. Use the WriteEvent method to write events using a localized message resource file.
I got the same exception when trying to install a service from the command line when using installutil in Windows 7. The solution was to open the command line as Administrator and then run installutil.
Also you may find it easier to use a framework like TopShelf to host your services, because it manages all the setup configuration from the name and description of the service to how your recovery process will work. It also allows to easily start your service from inside the IDE when you are debugging it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With