-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
52 lines (43 loc) · 1.22 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using sharp_potato;
using Vanara.PInvoke;
using static Vanara.PInvoke.Ole32;
using static Vanara.PInvoke.AdvApi32;
using static Vanara.PInvoke.Kernel32;
using static Vanara.PInvoke.Secur32;
var process = new SystemProcess();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/K whoami";
//process.StartInfo.RedirectStandardOutput = true;
//process.StartInfo.RedirectStandardError = true;
//process.StartInfo.RedirectStandardInput = true;
//process.StartInfo.CreateNoWindow = true;
process.Start();
Console.ReadLine();
new Thread(() =>
{
var buffer = new char[512];
while (true)
{
int charsRead = process.StandardOutput.Read(buffer);
Console.Out.Write(new string(buffer.Take(charsRead).ToArray()));
}
}).Start();
new Thread(() =>
{
var buffer = new char[512];
while (true)
{
int charsRead = process.StandardError.Read(buffer);
Console.Error.Write(new string(buffer.Take(charsRead).ToArray()));
}
}).Start();
while (!process.HasExited)
{
var line = Console.ReadLine();
process.StandardInput.WriteLine(line);
}
Console.Out.WriteLine("Exited");
Environment.Exit(0);