リンクありがとうございます。次のコードを使用してこれを実行することができました。使用するには、引き続きFWManagerオブジェクトを取得する必要があります。
private void btnBlock_Click(object sender, EventArgs e)
{
String IP = txtAddress.Text;
txtAddress.Clear();
if (IsAddressValid(IP))
{
INetFwRule2 firewallRule = (INetFwRule2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
firewallRule.Name = "BrutalNT: IP Access Block " + txtAddress.Text;
firewallRule.Description = "Block Incoming Connections from IP Address.";
firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;
firewallRule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN;
firewallRule.Enabled = true;
firewallRule.InterfaceTypes = "All";
firewallRule.RemoteAddresses = txtAddress.Text;
INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
firewallPolicy.Rules.Add(firewallRule);
String msg = "IP Address \"" + IP + "\" Blocked Successfully!";
MessageBox.Show(msg, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
String msg = "IP Address \"" + IP + "\" was Invalid!";
MessageBox.Show(msg, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}