https://www.cnblogs.com/code1992/p/11661078.html
/// <summary> /// 通过对象防火墙操作 /// </summary> /// <param name="isOpenDomain">域网络防火墙(禁用:false;启用(默认):true)</param> /// <param name="isOpenPublicState">公共网络防火墙(禁用:false;启用(默认):true)</param> /// <param name="isOpenStandard">专用网络防火墙(禁用: false;启用(默认):true)</param> /// <returns></returns> public static bool FirewallOperateByObject(bool isOpenDomain = true, bool isOpenPublicState = true, bool isOpenStandard = true) { try { INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2")); // 启用<高级安全Windows防火墙> - 专有配置文件的防火墙 firewallPolicy.set_FirewallEnabled(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE, isOpenStandard); // 启用<高级安全Windows防火墙> - 公用配置文件的防火墙 firewallPolicy.set_FirewallEnabled(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC, isOpenPublicState); // 启用<高级安全Windows防火墙> - 域配置文件的防火墙 firewallPolicy.set_FirewallEnabled(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN, isOpenDomain); } catch (Exception e) { string error = $"防火墙修改出错:{e.Message}"; throw new Exception(error); } return true; }
标签:FW,C#,启用,防火墙,firewallPolicy,操作,NET,true From: https://www.cnblogs.com/cnchengv/p/17752887.html