Updating existing firewall rule using API

前端 未结 3 1362
花落未央
花落未央 2021-02-06 02:02

I am able to pro grammatically add individual rules to the Windows Firewall (Server 2008 R2), however I am trying to avoid multiple rules per IP address, and would just like to

3条回答
  •  名媛妹妹
    2021-02-06 02:06

    The code below works for me:

    INetFwPolicy2 firewallPolicy = (INetFwPolicy2) Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
    
    var rule = firewallPolicy.Rules.Item("Block Bad IP Addresses"); // Name of your rule here
    rule.Name = "Block Block Block"; // Update the rule here. Nothing else needed to persist the changes
    

提交回复
热议问题