Remove Windows Firewall Rule (Exception) using Delphi -


i trying manage firewall rules (exceptions) on windows 7 using delphi xe3. found interesting code adding rule windows firewall, nothing deleting (removing) it. please, can help?

here code adding 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!

you call inetfwrules.remove, passing in name of rule. name same name used when creating (robject.name in code you've provided above).

// note: normal com exception handling should used. omitted clarity.  procedure removeexceptfromfirewall(const rulename: string); const   net_fw_profile2_private = 2;   net_fw_profile2_public  = 4; var   profile: integer;   policy2: olevariant;   robject: olevariant; begin   profile := net_fw_profile2_private or net_fw_profile2_public;   policy2 := createoleobject('hnetcfg.fwpolicy2');   robject := policy2.rules;   robject.remove(rulename); end; 

there's nothing provided in linked documentation, btw. provided link reference.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -