Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. int ProcessStartOk333(string path, string name, Boolean start)
  2. {
  3. string processName = name;
  4. var processExists = Process.GetProcesses().Any(p => p.ProcessName == processName);
  5. var process = Process.GetProcesses().FirstOrDefault(p => p.ProcessName == processName);
  6. if (!processExists && start == true)
  7. {
  8. string processPath = path;
  9. var startInfo = new ProcessStartInfo(processPath)
  10. { Verb = "runas" };
  11. startInfo.Password = ReadPassword(textBox2.Text); //попытка ввести пароль администратора таким образом
  12. startInfo.UserName = textBox3.Text;
  13. Process.Start(startInfo); //есть запуск
  14. // MessageBox.Show("запустили");
  15. }
  16. }
  17.  
  18. public static SecureString ReadPassword(string password)
  19. {
  20. SecureString secPass = new SecureString();
  21. for (int i = 0; i < password.Length; i++)
  22. secPass.AppendChar(password[i]);
  23. return secPass;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement