Do not forget to reference ActiveX and comobj.
Const
Net_fw_profile_domain = 0;
Net_fw_profile_standard = 1;
Net_fw_ip_version_any = 2;
Net_fw_ip_protocol_udp = 17;
Net_fw_ip_protocol_tcp = 6;
Net_fw_scope_all = 0;
Net_fw_scope_local_subnet = 1;
Procedure addporttofirewall (entryname: string; portnumber: Cardinal );
VaR
Fwmgr, Port: olevariant;
Profile: olevariant;
Begin
Fwmgr: = createoleobject ('hnetcfg. fwmgr ');
Profile: = fwmgr. localpolicy. currentprofile;
Port: = createoleobject ('hnetcfg. fwopenport ');
Port. Name: = entryname;
Port. Protocol: = net_fw_ip_protocol_tcp;
Port. Port: = portnumber;
Port. Scope: = net_fw_scope_all;
Port. Enabled: = true;
Profile. globallyopenports. Add (port );
End;
Procedure addapplicationtofirewall (entryname: string; applicationpathandexe: string );
VaR
Fwmgr, app, Port: olevariant;
Profile: olevariant;
Begin
Fwmgr: = createoleobject ('hnetcfg. fwmgr ');
Profile: = fwmgr. localpolicy. currentprofile;
APP: = createoleobject ('hnetcfg. fwauthorizedapplication ');
App. processimagefilename: = applicationpathandexe;
App. Name: = entryname;
App. Scope: = net_fw_scope_all;
App. ipversion: = net_fw_ip_version_any;
App. Enabled: = true;
Profile. authorizedapplications. Add (APP );
End;
// More things you can see at this address: http://msdn2.microsoft.com/en-us/library/aa366415.aspx