I know many of you guys will think this problem is a duplicate and already solve before, but I having trouble in this problem and I am really frustrated right now because I can't solve this.
This is the first time I work with Windows Service, I wanted to Install my Service programmatically and I came up with this solution:
ServiceProcessInstaller ProcesServiceInstaller = new ServiceProcessInstaller();
ProcesServiceInstaller.Account = ServiceAccount.LocalSystem;
/**
I already try to used this
ProcesServiceInstaller.Account = ServiceAccount.LocalService;
ProcesServiceInstaller.Username = null;
ProcesServiceInstaller.Password = null;
**/
ServiceInstaller ServiceInstallerObj = new ServiceInstaller();
InstallContext Context = new System.Configuration.Install.InstallContext();
String path = String.Format("/assemblypath={0}", @"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
String[] cmdline = { path };
Context = new System.Configuration.Install.InstallContext("Service-Install.log", cmdline);
ServiceInstallerObj.Context = Context;
ServiceInstallerObj.DisplayName = serviceName;
ServiceInstallerObj.Description = "Sample Description";
ServiceInstallerObj.ServiceName = serviceName;
ServiceInstallerObj.StartType = ServiceStartMode.Automatic;
ServiceInstallerObj.Parent = ProcesServiceInstaller;
System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
ServiceInstallerObj.Install(state);
the above code is working and I can see it in my Services
.
but everytime I right click on it and try to Start the Service I get this error:
Windows could not start the [service name] service on Local Computer.
Error 5: Access is Denied.
I search for solution but none of this are working:
First I configure my manifest with this:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Second this link: Link1 and Link2
by doing the below
*Right-click on top-level folder containing the service executable. Go to Properties
*Go to "Security" Tab
*Click "EDIT"
*Click "ADD"
*Enter the name "SYSTEM","NETWORK SERVICE", "SERVICE" click OK (I already add this 3 account)
*Highlight "SYSTEM","NETWORK SERVICE", "SERVICE" user, and click ALLOW check-box next to "Full control"
*Click OK twice
and nothing is working.
UPDATE
The below image is the Security Permission I added.
and I already allow all the checkboxes*(Except the Deny)* specially the full control.
and the below image is what I have in Windows Event Viewer.
and the Error is Access Denied
anyone please can help me? Thank you!