2
votes

When I use Win32 API CreateProcessAsUser() to execute a program with impersonated user in my C# .NET project, it was successful.

But I want implement that using .NET Framework API.

There is a similar method like System.Diagnostics.Process.Start() But it's not exactly same as CreateProcessAsUser().

The function CreateProcessAsUser() receives "hToken" at the first parameter. So when I duplicate a token and use it to that function, I can impersonate a user and execute a program with that user.

But the method System.Diagnostics.Process.Start() doesn't provide such a parameter.

If there is anyone who knows this, would you please let me know? Thanks

2

2 Answers

2
votes

ProcessStartInfo has UserName and Password properties in NET 2.0 or greater.

1
votes

There is no native solution. I'm sorry I disappointed you.

As Microsoft's Knowledge Base advises, You can do it only through P/Invocation (exactly like you do): https://support.microsoft.com/en-us/kb/889251