“ netsh”命令的替代方法->使用对象?

时间:2019-01-29 12:33:28

标签: c# netsh

在我当前的课程中,我正在使用一些“ 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();
    }

0 个答案:

没有答案