C #: load roaming profile and execute program as user
In the application, I need to execute other programs with different user credentials. I am currently using System.Diagnostics.Process.Start to execute the program:
public static Process Start(
string fileName,
string arguments,
string userName,
SecureString password,
string domain
)
However, this function does not download the roaming profile from the network - which is required.
I could use "runas / profile ..." to load the profile and execute the command, but that would require a password. There must be a more elegant way ...
But where?
+1
source to share
2 answers
My solution (based on leppie's hint):
Process p = new Process();
p.StartInfo.FileName = textFilename.Text;
p.StartInfo.Arguments = textArgument.Text;
p.StartInfo.UserName = textUsername.Text;
p.StartInfo.Domain = textDomain.Text;
p.StartInfo.Password = securePassword.SecureText;
p.StartInfo.LoadUserProfile = true;
p.StartInfo.UseShellExecute = false;
try {
p.Start();
} catch (Win32Exception ex) {
MessageBox.Show("Error:\r\n" + ex.Message);
}
+5
source to share