Código de una función para agregar un puerto como excepción al firewall de Windows XP SP2.
Truco basado a su vez en el truco 382 (Como agregar una aplicación al firewall de Windows).
Código Delphi
[-]
uses
ComObj;
const
NET_FW_SCOPE_ALL = 0;
NET_FW_SCOPE_LOCAL_SUBNET = 1;
NET_FW_IP_PROTOCOL_TCP = 6;
NET_FW_IP_PROTOCOL_UDP = 17;
procedure AgregarPuerto(APort: Integer; AName: string);
var
fwMgr: Variant;
Profile: Variant;
Port: Variant;
begin
fwMgr := CreateOleObject('HNetCfg.FwMgr');
Profile := fwMgr.LocalPolicy.CurrentProfile;
Port := CreateOleObject('HNetCfg.FwOpenPort');
Port.Name := AName;
Port.Protocol := NET_FW_IP_PROTOCOL_TCP; Port.Port := APort;
Port.Scope := NET_FW_SCOPE_ALL;
Port.Enabled := TRUE;
Profile.GloballyOpenPorts.Add(Port);
end;