首页 > 解决方案 > “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();
    }

标签: c#netsh

解决方案


推荐阅读