2 回答
TA貢獻1799條經驗 獲得超8個贊
ProcessStartInfo.RedirectStandardOutput在實例化 whoami 時使用。您可以解析為 logonid 獲得的文本。
TA貢獻1799條經驗 獲得超6個贊
您可以使用ProcessStartInfo.RedirectStandardInput和ProcessStartInfo.RedirectStandardoutput屬性來實現這一點。
以下是示例代碼:
public static string GetLoginId()
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.Start();
StreamWriter myStreamWriter = p.StandardInput;
myStreamWriter.WriteLine("whoami /logonid");
// To avoid deadlocks, always read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(output);
}
- 2 回答
- 0 關注
- 302 瀏覽
添加回答
舉報
