question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strategy for Process.Start and Impersonation

See original GitHub issue

Hello 😃

I am trying to start a process with different rights from the inside of an windows service.

If i impersonate like this:

Impersonation.RunAsUser(credentials, LogonType.Interactive, () => {
                      ProcessStartInfo info = new ProcessStartInfo(cmd_name, parameters);

                    info.UseShellExecute = false;
                    info.CreateNoWindow = true;
                    info.RedirectStandardOutput = true;
                    console.StartInfo = info;
                    console.Start();

                    message = console.StandardOutput.ReadToEnd();
                    });

the process will still run as local system. If i set the Credentials also in the ProcessStartInfo Class, i get an Access Denied.

Currently i am using an implementation of the native call “CreateProcessAsUserW” but i was looking for an working solution with the Process Class of .NET

Thank you 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
mattjohnsonpintcommented, Sep 13, 2018

I did some research on this, and I believe that the ProcessStartInfo approach will not work in any case - regardless of the execution context - because you are running inside a Windows Service. All docs and blogs point at CreateProcessAsUser, so I would continue that approach.

I may consider adding another method to this library in the future, such as Impersonation.StartProcessAsUser which would make the appropriate calls (either through ProcessStartInfo or CreateProcessAsUser depending on environment). I’ll leave this issue open to remind me.

1reaction
PatrickSchmidtSEcommented, Sep 18, 2018

Thank you for your fast answer 😃 That would be a great addition to your library and make it even more powerful!

Just as an addition as i also ran in those issues… Simply starting the process over the CreateProcessAsUser method is not that hard, but mostly if users start processes they also want to access stdin/stdout and react to it. This is a little bit more difficult, because you need to create pipes.

I dont know if you want to handle that too, but just as feedback, that in this case, stdin/stdout handling is a often needed use case 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strategy for Process.Start and Impersonation · Issue #31
I am trying to start a process with different rights from the inside of an windows service. If i impersonate like this: Impersonation.RunAsUser( ......
Read more >
c# - Process.Start() impersonation problem
Trying to start process with another access token, without success, it runs as the non-impersonated user. ... How to make this work properly?...
Read more >
Process.Start and Impersonation
NETthread invoking the Start method is impersonating a client, the Process still starts with the ASP.NET worker process credentials.
Read more >
Spawn process under impersonated user - ASP.NET
This step-by-step article describes how to spawn a process that runs under the context of the impersonated user in ASP.NET pages.
Read more >
Getting Started with Impersonation
Click the Impersonate button. · Enter the reason why you're impersonating them, and then click Start Impersonation Session. You'll only be able ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found