code_junkie

C#: Load roaming profile and execute program as user

Nov 12th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public static Process Start(
  2. string fileName,
  3. string arguments,
  4. string userName,
  5. SecureString password,
  6. string domain
  7. )
  8.  
  9. Process p = new Process();
  10.  
  11. p.StartInfo.FileName = textFilename.Text;
  12. p.StartInfo.Arguments = textArgument.Text;
  13. p.StartInfo.UserName = textUsername.Text;
  14. p.StartInfo.Domain = textDomain.Text;
  15. p.StartInfo.Password = securePassword.SecureText;
  16.  
  17. p.StartInfo.LoadUserProfile = true;
  18. p.StartInfo.UseShellExecute = false;
  19.  
  20. try {
  21. p.Start();
  22. } catch (Win32Exception ex) {
  23. MessageBox.Show("Error:rn" + ex.Message);
  24. }
Add Comment
Please, Sign In to add comment