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();
}
解决方案
推荐阅读
- c# - python to c#(关于服务器请求)
- android - 如何在生成密钥之前检查 StrongBox Keymaster 硬件的可用性?
- three.js - 是否可以在 THREE.Object3D 上应用旋转/缩放/位置
- pandas-groupby - 如何计算一周中每天的平均人数?
- scala - 从数据集的行中选择一列
- r - 如何将 sapply 代码转换为 vapply 代码
- pytorch - Pytorch model.train() 和 model.eval() 行为怪异
- c# - dotnet build 间歇性退出,并在 linux 上出现分段错误(核心转储)或 139
- javascript - 如何在每 20 秒显示 5 秒后关闭此元素
- python - 不要为我的 GAN 实现获得完整的 GPU 利用率