Guest User

Untitled

a guest
Jul 14th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Security;
  5. using System.Text;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.  
  10. class Program
  11. {
  12.  
  13. private ProcessStartInfo programStartInfo = new ProcessStartInfo
  14. {
  15.  
  16. RedirectStandardOutput = true,
  17. RedirectStandardError = true,
  18. RedirectStandardInput = true,
  19.  
  20. StandardOutputEncoding = Encoding.UTF8,
  21. StandardErrorEncoding = Encoding.UTF8,
  22.  
  23. UseShellExecute = false,
  24. LoadUserProfile = false,
  25. CreateNoWindow = true,
  26. WindowStyle = ProcessWindowStyle.Hidden,
  27. ErrorDialog = false,
  28.  
  29. Arguments = "/K echo %username%",
  30. FileName = "cmd.exe",
  31. WorkingDirectory = "C:\\Windows\\System32\\"
  32.  
  33. };
  34.  
  35. public static void Main(string[] args)
  36. {
  37.  
  38. new Program().Run();
  39.  
  40. }
  41.  
  42. void Run()
  43. {
  44.  
  45. var proc = new Process{
  46.  
  47. StartInfo = programStartInfo,
  48. EnableRaisingEvents = true,
  49.  
  50. };
  51.  
  52. proc.StartInfo.UserName = "SimplePM_StartUser";
  53.  
  54. proc.StartInfo.LoadUserProfile = true;
  55.  
  56. var encPassword = new SecureString();
  57.  
  58. foreach (var c in "1234567890")
  59. encPassword.AppendChar(c);
  60.  
  61. proc.StartInfo.Password = encPassword;
  62.  
  63. proc.OutputDataReceived += proc_OutputDataReceived;
  64.  
  65. proc.Start();
  66.  
  67. proc.BeginOutputReadLine();
  68.  
  69. if (!proc.WaitForExit(5000))
  70. {
  71.  
  72. try
  73. {
  74. proc.Kill();
  75. }
  76. catch { }
  77.  
  78. }
  79.  
  80. }
  81.  
  82. private void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
  83. {
  84.  
  85. if (e.Data == null)
  86. return;
  87.  
  88. File.AppendAllText("E:\\1.txt", e.Data.TrimEnd());
  89.  
  90. Console.WriteLine(e.Data.TrimEnd());
  91.  
  92. }
  93.  
  94. }
  95.  
  96. }
Add Comment
Please, Sign In to add comment