Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public void req(string app, string att)
  2. {
  3. var user = "administrator";
  4. var password = "password";
  5. var domain = "domain";
  6. var securePass = new SecureString();
  7. foreach (char c in password)
  8. {
  9. securePass.AppendChar(c);
  10. }
  11.  
  12. // создаем процесс cmd.exe с параметрами
  13. ProcessStartInfo psiOpt = new ProcessStartInfo(app, att);
  14. // скрываем окно запущенного процесса
  15. psiOpt.WindowStyle = ProcessWindowStyle.Hidden;
  16. psiOpt.RedirectStandardOutput = true;
  17. psiOpt.UseShellExecute = false;
  18. psiOpt.UserName = user;
  19. psiOpt.Password = securePass;
  20. psiOpt.Domain = domain;
  21. psiOpt.CreateNoWindow = true;
  22. psiOpt.StandardOutputEncoding = Encoding.GetEncoding(866);
  23. // запускаем процесс
  24. Process procCommand = Process.Start(psiOpt);
  25. // получаем ответ запущенного процесса
  26.  
  27. using (StreamReader srIncoming = procCommand.StandardOutput)
  28. // выводим результат
  29. while (true)
  30. {
  31. // Читаем строку из файла во временную переменную.
  32. string temp = srIncoming.ReadLine();
  33.  
  34. // Если достигнут конец файла, прерываем считывание.
  35. if (temp == null) break;
  36.  
  37.  
  38. _textBox.Text += temp + "n";
  39.  
  40. }
  41.  
  42.  
  43. // закрываем процесс
  44. procCommand.WaitForExit();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement