Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Agregar un puerto al firewall de Windows (https://www.clubdelphi.com/foros/showthread.php?t=80804)

jorge82 02-06-2007 08:19:01

Agregar un puerto al firewall de Windows
 
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');
   // El nombre con el que aparecerá la excepción en el Firewall de Windows.
   Port.Name := AName;
   Port.Protocol := NET_FW_IP_PROTOCOL_TCP; // O NET_FW_IP_PROTOCOL_UDP, si el puerto es UDP. 
   Port.Port := APort;
   // El puerto tiene un alcance global, si quieres que el alcance del puerto solo sea una
   // subred local entonces Port.Scope := NET_FW_SCOPE_LOCAL_SUBNET; 
   Port.Scope := NET_FW_SCOPE_ALL;  
   Port.Enabled := TRUE;
   // Agregamos el puerto al firewall.
   Profile.GloballyOpenPorts.Add(Port);
end;


La franja horaria es GMT +2. Ahora son las 14:51:09.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi