In an impersonation scenario related to Sharepoint I need to execute some code in a separate process (the process will run in the context of a certain user). I do not want to launch a separate application, basically I want to do a ‘run as’ on just a method.
In an impersonation scenario related to Sharepoint I need to execute some code in
Share
The Process.Start method has an overload to start the process provided you have the appropriate user, password and domain.
What you want to do is create a ProcessStartInfo object and specify the proper UserName and Password when starting the process. So you can do something like this:
Oh, Process is in the System.Diagnostics namespace if it isn’t already imported for your project.
EDIT: Quick sidenote, the password field is actually a SecureString type object, so MSDN suggests filling the value in this way: