Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a Windows App using a specific User account

I need to ensure that my widnows app (winform not console) runs under a certain user account (in other words any user can be logged on to the maching but the .exe will always execute as the specified user).

Can this be done programtically? If so, how?

like image 621
Robert Avatar asked Dec 11 '25 17:12

Robert


1 Answers

You can start the application like this:

ProcessStartInfo psi = new ProcessStartInfo(myPath);
psi.UserName = username;

SecureString ss = new SecureString();
foreach (char c in password)
{
 ss.AppendChar(c);
}

psi.Password = ss;
psi.UseShellExecute = false;
Process.Start(psi);
like image 118
Simon Mourier Avatar answered Dec 14 '25 20:12

Simon Mourier