Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Security;
- using System.Text;
- namespace ConsoleApp1
- {
- class Program
- {
- private ProcessStartInfo programStartInfo = new ProcessStartInfo
- {
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- RedirectStandardInput = true,
- StandardOutputEncoding = Encoding.UTF8,
- StandardErrorEncoding = Encoding.UTF8,
- UseShellExecute = false,
- LoadUserProfile = false,
- CreateNoWindow = true,
- WindowStyle = ProcessWindowStyle.Hidden,
- ErrorDialog = false,
- Arguments = "/K echo %username%",
- FileName = "cmd.exe",
- WorkingDirectory = "C:\\Windows\\System32\\"
- };
- public static void Main(string[] args)
- {
- new Program().Run();
- }
- void Run()
- {
- var proc = new Process{
- StartInfo = programStartInfo,
- EnableRaisingEvents = true,
- };
- proc.StartInfo.UserName = "SimplePM_StartUser";
- proc.StartInfo.LoadUserProfile = true;
- var encPassword = new SecureString();
- foreach (var c in "1234567890")
- encPassword.AppendChar(c);
- proc.StartInfo.Password = encPassword;
- proc.OutputDataReceived += proc_OutputDataReceived;
- proc.Start();
- proc.BeginOutputReadLine();
- if (!proc.WaitForExit(5000))
- {
- try
- {
- proc.Kill();
- }
- catch { }
- }
- }
- private void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
- {
- if (e.Data == null)
- return;
- File.AppendAllText("E:\\1.txt", e.Data.TrimEnd());
- Console.WriteLine(e.Data.TrimEnd());
- }
- }
- }
Add Comment
Please, Sign In to add comment