Closed mauleshmevada closed 7 years ago
Looks, like you are doing something wrong. Look at this thread https://github.com/murrayju/CreateProcessAsUser/issues/4
It sounds like you are saying that you are trying to run the service under a non-privileged system account. This will not work, the Windows APIs being called require elevated permissions, which the local system account has.
im getting the same error; however, I am running the service as Local System
Weirdly, your solution works perfectly, while my service fails. Both are using Local System and are Automatic startup.
System.Exception: StartProcessAsCurrentUser: GetSessionUserToken failed. at SecurityService.ProcessExtensions.StartProcessAsCurrentUser(String appPath, String cmdLine, String workDir, Boolean visible) in C:\Users\Me\Programs\C#\Me\SVC\SVC 4\Super\Super Security\SecurityService\ProcessExtensions.cs:line 224 at SecurityService.SecurityService.OnStart(String[] args) in C:\Users\Me\Programs\C#\Me\SVC\SVC 4\Super\Super Security\SecurityService\SecurityService.cs:line 49
Weirdly, your solution works perfectly, while my service fails. Both are using Local System and are Automatic startup.
Well, bridge the gap then. Change one solution one step at a time to bring it closer to the other. Sooner or later you'll find where you broke it. Or you won't, but you'll end up with a working solution anyway =)
it doesnt work if service file in a user folder. such Documents, Desktop, or any folder in [HomeDrive]\Users\username folder so move your service file into somewhere which all users can reach like C: drive.
I fixed it. Oddly enough, the problem was solved by simply creating a new solution and copying the code to the user (not the designer) source files. Perhaps something was wrong with the designer files or the csproj.
Looks like this is resolved.
Hi Friends,
I am trying to write a windows service that will reconnect the vpn connection if disconnected, I have implemented your code, and it is working fine only when the users logs in immediately. Otherwise if no user is logged in to windows the service will not start. [see attached event viewer error]
I have tried delayed start, restart service after some time, but non works without users being logged in. Is there any way to bypass that or something. I have done some reading, what about using CreateProcessWithLogonW, instead of CreateProcessAsUser. anyone tried anything like that. Thank you very much in advance guys,
I had run your program it successfully started with local system account but didn't work with specific user account. I get the following exception in the event viewer,
Service cannot be started. System.Exception: StartProcessAsCurrentUser: GetSessionUserToken failed. at murrayju.ProcessExtensions.ProcessExtensions.StartProcessAsCurrentUser(String appPath, String cmdLine, String workDir, Boolean visible) in c:\Users\indianic\Downloads\CreateProcessAsUser-master\CreateProcessAsUser-master\ProcessExtensions\ProcessExtensions.cs:line 224 at demo.DemoService.OnStart(String[] args) in c:\Users\indianic\Downloads\CreateProcessAsUser-master\CreateProcessAsUser-master\DemoService\DemoService.cs:line 15 at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
Thanks.