1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| // Inclure dans ComObj ActiveX et utilise la clause (également pour les variantes et D6 et +)
const
NET_FW_PROFILE_DOMAIN = 0;
NET_FW_PROFILE_STANDARD = 1;
const
NET_FW_IP_PROTOCOL_TCP = 6;
NET_FW_IP_PROTOCOL_UDP = 17;
const
NET_FW_SCOPE_ALL = 0;
const
NET_FW_IP_VERSION_ANY = 2;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var ovMgr: OleVariant;
ovProfile: OleVariant;
ovPort: OleVariant;
begin
// Créer une interface de gestion
ovMgr:=CreateOleObject('HNetCfg.FwMgr');
// La protection des ressources
try
// Obtenirun profil local interface
ovProfile:=ovMgr.LocalPolicy.CurrentProfile;
// La protection des ressources
try
// Créer un nouveau port
ovPort:=CreateOleObject('HNetCfg.FwOpenPort');
try
// Définir les propriétés du port
ovPort.Port:=81;
ovPort.Name:='Whatever';//nom du port
ovPort.Scope:=NET_FW_SCOPE_ALL;
ovPort.IpVersion:=NET_FW_IP_VERSION_ANY;
ovPort.Protocol:=NET_FW_IP_PROTOCOL_TCP;
ovPort.Enabled:=True;
// La protection des ressources
try
// Ajouter à l'échelle globale des ports ouverts
ovProfile.GloballyOpenPorts.Add(ovPort);
////
// .... faire "whatever" ....
////
finally
// Retirer de l'échelle globale des ports ouverts
ovProfile.GloballyOpenPorts.Remove(81, NET_FW_IP_PROTOCOL_TCP);
end;
finally
// Interface de sortie
ovPort:=Unassigned;
end;
finally
// Interface de sortie
ovProfile:=Unassigned;
end;
finally
// Interface de sortie
ovMgr:=Unassigned;
end;
end; |
Partager