//创建防火墙策略类的实例 INetFwPolicy2 policy2 = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2")); foreach (INetFwRule item in policy2.Rules) { //存在相同名称和端口的时候返回 if (item.Name == name&&item.LocalPorts.Tr