I created a window service and to install it I created its deployment project and installed that. After installing I stared it. It successfully started.
Next day I made some modification, and rebuild and reinstalled but now its not installing.
Then I thought its issue with installer, lets create a custom installer for service so that anytime I can update my code.
I created it like this incase if anyone need this for future.
public class MyInstaller : Installer { ServiceProcessInstaller spi; ServiceInstaller si; public MyInstaller() { spi = new ServiceProcessInstaller(); spi.Account = ServiceAccount.LocalSystem; si = new ServiceInstaller(); si.StartType = ServiceStartMode.Manual; si.ServiceName = "MyService"; si.DisplayName = "My Service"; si.Description = "service installed from command line"; this.Installers.Add(spi); this.Installers.Add(si); } }
I called it from main method by check the parameter args.
case "-i": case "-install": ti = new TransactedInstaller(); mi = new MyInstaller(); ti.Installers.Add(mi); string logPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\install.log"; ctx = new InstallContext(logPath, cmdline); ti.Context = ctx; //.Context ( ctx ); ti.Install(new Hashtable()); break;
Now when I am trying to install. I recevied error System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
I google it, and come to know service will try to access application log while installing and write log there.
I am not writing any event log. I have my log4net for logging. But still its default behaviour.
How to overcome this issue now? Its not getting installed even I have all permissions.
Thanks
I have found that at times you may need to "Run as Administrator". If you are installing from a command prompt you may need to start that up with "Run as Administrator".
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