在我当前的课程中,我正在使用一些“ netsh”调用。由于我不想为此使用CMD,因此在c#中是否有其他方法可以将其保存到对象中?
private void ExecuteNetshCheckUrlacl(string protocol, int port, string testfilenamepath)
{
OutputHandler.ColorCMDOutput(" + Port " + port, ConsoleColor.Gray);
Process netsh = new Process();
netsh.StartInfo.FileName = "netsh.exe";
netsh.StartInfo.Arguments = "http show urlacl " + protocol + "://+:" + port.ToString() + "/";
netsh.StartInfo.UseShellExecute = false;
netsh.StartInfo.RedirectStandardOutput = true;
netsh.Start();
{
using (StreamReader reader = netsh.StandardOutput)
{
string result = reader.ReadToEnd();
OutputHandler.WriteDataToFileOrOverwrite(testfilenamepath, result);
}
}
netsh.WaitForExit();
netsh.Dispose();
}