【发布时间】:2014-12-05 19:44:54
【问题描述】:
我正在尝试使用 Delphi XE3 在 Windows 7 上管理防火墙规则(例外)。我发现了一个非常有趣的代码,用于向 Windows 防火墙添加规则,但没有删除(删除)它。请问,有人可以帮忙吗?
添加规则的代码如下:
procedure AddExceptToFirewall(const Caption, AppPath: String);
// Uses ComObj
const
NET_FW_PROFILE2_PRIVATE = 2;
NET_FW_PROFILE2_PUBLIC = 4;
NET_FW_IP_PROTOCOL_TCP = 6;
NET_FW_ACTION_ALLOW = 1;
var
Profile: Integer;
Policy2: OleVariant;
RObject: OleVariant;
NewRule: OleVariant;
begin
Profile := NET_FW_PROFILE2_PRIVATE OR NET_FW_PROFILE2_PUBLIC;
Policy2 := CreateOleObject('HNetCfg.FwPolicy2');
RObject := Policy2.Rules;
NewRule := CreateOleObject('HNetCfg.FWRule');
NewRule.Name := Caption;
NewRule.Description := Caption;
NewRule.ApplicationName := AppPath;
NewRule.Protocol := NET_FW_IP_PROTOCOL_TCP;
NewRule.Enabled := True;
NewRule.Grouping := '';
NewRule.Profiles := Profile;
NewRule.Action := NET_FW_ACTION_ALLOW;
RObject.Add(NewRule);
end;
谢谢!
【问题讨论】:
标签: windows delphi exception firewall rule