Strategy for Process.Start and Impersonation
See original GitHub issueHello 😃
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:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 atCreateProcessAsUser
, 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 throughProcessStartInfo
orCreateProcessAsUser
depending on environment). I’ll leave this issue open to remind me.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 😃