有没有人知道是否有一个现有的C#.NET名称空间包含相当于IPHelper函数的WMI?具体来说,我需要打电话给CreateIpForwardEntry和DeleteIpForwardEntry。是通过P/Invoke的唯一途径吗?(注意:这不是对第三方库的请求,而是对标准.NET库的请求)
发布于 2014-02-21 13:43:55
最后,我决定不去尝试调用WMI IPHelper函数。简单地启动一个进程、打开cmd.exe并编写控制台命令来添加和删除路由就容易多了。下面的代码说明了如何做到这一点。
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
CreateNoWindow = true
}
};
proc.Start();
proc.StandardInput.WriteLine(delete
? "route delete " + ServiceIpAddress + " mask " + GatewayMask + " " + GatewayIpAddress + " -p" : "route add " + ServiceIpAddress + " mask " + GatewayMask + " " + GatewayIpAddress + " -p");
roc.Close();https://stackoverflow.com/questions/21888599
复制相似问题