Reputation: 29
I have a GUI process that is running as nt authority\system. I'd like to launch another process (preferably via Process
class) as the user that is interacting with the GUI process. If I just call Process.Start
the new process will also run as nt authority\system but I want it to be domain\user.
Edit: for clarification, I don't have the current user's username or password. I just want to run the process as though the user was starting it themselves without having to ask for username/password.
Upvotes: 2
Views: 412
Reputation: 1258
'run as' argument while invoking a process with Process object, will ask for password of the user.
It is not possible to run a process as User account from a Local System Account.
You can do a workaround to solve your problem
Start a Main Process 'A' as the logged on user.
Now, start the required Local System Account 'B' process from the Main Process(A).
Now 'A' will monitor for a trigger from process B, if the main code (the code that must be run in user account) needs to be run. If the trigger hits, the required code can be run.
Monitoring can be done by monitoring(reading) a text file for every certain duration, and the trigger can be sent from B(system account process) which is writing to the text file. Any other better monitoring approach can be taken.
Upvotes: 0
Reputation: 11263
var psi = new ProcessStartInfo();
psi.Verb = "runas";
psi.FileName = "notepad.exe";
Process.Start(psi);
Upvotes: 1
Reputation: 4883
You can do this:
Process proc = new System.Diagnostics.Process();
System.Security.SecureString ssPwd = new System.Security.SecureString();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "C:/YourPath/YourProcess.exe";
proc.StartInfo.Arguments = "Args"; //Arguments if any, otherwise delete this line
proc.StartInfo.Domain = "domainname";
proc.StartInfo.UserName = "username";
proc.StartInfo.Password = "password";
proc.Start();
Upvotes: 1
Reputation: 10807
Use StartInfo property with a valid credentials.
Process proc = new Process();
proc.StartInfo.Domain = "YourDomain";
proc.StartInfo.UserName = "Username";
proc.StartInfo.Password = "YourPassword";
Upvotes: 1