I am trying to manage firewall rules (exceptions) in Windows 7 using Delphi XE3. I found very interesting code to add a rule to the Windows firewall, but did not delete (delete) it. Can someone please help?
Here is the code to add the rule:
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;
Thanks!
source share