murrayju / CreateProcessAsUser

Creates a process in a different Windows session
MIT License
369 stars 114 forks source link

Didnt work with Login as specific User account #8

Closed mauleshmevada closed 7 years ago

mauleshmevada commented 8 years ago

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.

AndrewSav commented 8 years ago

Looks, like you are doing something wrong. Look at this thread https://github.com/murrayju/CreateProcessAsUser/issues/4

murrayju commented 8 years ago

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.

ghost commented 8 years ago

im getting the same error; however, I am running the service as Local System

ghost commented 8 years ago

Weirdly, your solution works perfectly, while my service fails. Both are using Local System and are Automatic startup.

ghost commented 8 years ago

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

AndrewSav commented 8 years ago

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 =)

trksyln commented 8 years ago

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.

ghost commented 8 years ago

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.

murrayju commented 7 years ago

Looks like this is resolved.

toqilula commented 7 years ago

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,

Kind Regards Fatos, Kosovo

error