CreateProcessAsUser() in C# .NET Framework API (NOT Win32 API)

1.3k views Asked by At

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

There are 2 answers

1
user12864 On

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

0
Vizor On

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