I am trying to launch a new process as a user with Administrative privileges using impersonation:
In the above code, the current process from the Task Manager retains the original username after impersonation begins. Also, when msconfig is launched, it does not have the Administrator username and it complains about not having Administrative privileges.
How do I start msconfig using a different username and password?
I have no trouble doing this if I use RunAs from the command prompt.
How do I do this from in my program?
Code:
//A token for the Administrator previously obtained
//using LogonUser and DuplicateToken API calls
IntPtr ptrToken;
WindowsIdentity wid = new WindowsIdentity(ptrToken);
WindowsImpersonationContext imp = wid.Impersonate();
//This now returns the administrator name correctly
WindowsIdentity.GetCurrent().Name
Process prc = new Process();
prc.StartInfo.FileName = "msconfig";
prc.StartInfo.UseShellExecute = false;
prc.Start();
imp.Undo();
In the above code, the current process from the Task Manager retains the original username after impersonation begins. Also, when msconfig is launched, it does not have the Administrator username and it complains about not having Administrative privileges.
How do I start msconfig using a different username and password?
I have no trouble doing this if I use RunAs from the command prompt.
How do I do this from in my program?