Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void req(string app, string att)
- {
- var user = "administrator";
- var password = "password";
- var domain = "domain";
- var securePass = new SecureString();
- foreach (char c in password)
- {
- securePass.AppendChar(c);
- }
- // создаем процесс cmd.exe с параметрами
- ProcessStartInfo psiOpt = new ProcessStartInfo(app, att);
- // скрываем окно запущенного процесса
- psiOpt.WindowStyle = ProcessWindowStyle.Hidden;
- psiOpt.RedirectStandardOutput = true;
- psiOpt.UseShellExecute = false;
- psiOpt.UserName = user;
- psiOpt.Password = securePass;
- psiOpt.Domain = domain;
- psiOpt.CreateNoWindow = true;
- psiOpt.StandardOutputEncoding = Encoding.GetEncoding(866);
- // запускаем процесс
- Process procCommand = Process.Start(psiOpt);
- // получаем ответ запущенного процесса
- using (StreamReader srIncoming = procCommand.StandardOutput)
- // выводим результат
- while (true)
- {
- // Читаем строку из файла во временную переменную.
- string temp = srIncoming.ReadLine();
- // Если достигнут конец файла, прерываем считывание.
- if (temp == null) break;
- _textBox.Text += temp + "n";
- }
- // закрываем процесс
- procCommand.WaitForExit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement