Fórum Criar regra no Firewall do Windows pelo Delphi #337220
02/02/2007
0
alguém sabe se é possível, pelo Delphi por código, criar uma regra no firewall do windows que pertmita conexão na porta 3050 do Firebird?
atualmente eu faço isso manual, mas se tiver como via código seria muito melhor...
abraços
Eniorm
Curtir tópico
+ 0Posts
03/02/2007
Nasguone
http://www.codeproject.com/w2k/WinXPSP2Firewall.asp
Espero que te ajude
E.C.S
Gostei + 0
03/02/2007
Nasguone
// Inclua ActiveX e ComObj na clausula uses clause (Só funfa se for do D6 para cima)
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
// Cria interface administrativa
ovMgr:=CreateOleObject(´HNetCfg.FwMgr´);
// Proteção de recurso
try
// Cham interface do profile local
ovProfile:=ovMgr.LocalPolicy.CurrentProfile;
// Proteção de recurso
try
// Cria porta de interface
ovPort:=CreateOleObject(´HNetCfg.FwOpenPort´);
try
// Seta a propriedade da porta
ovPort.Port:=81;
ovPort.Name:=´Whatever´;
ovPort.Scope:=NET_FW_SCOPE_ALL;
ovPort.IpVersion:=NET_FW_IP_VERSION_ANY;
ovPort.Protocol:=NET_FW_IP_PROTOCOL_TCP;
ovPort.Enabled:=True;
// Proteção de Rc
try
// Adiciona portas globais ovProfile.GloballyOpenPorts.Add(ovPort);
finally
// Remove portas globais abertas
ovProfile.GloballyOpenPorts.Remove(81, NET_FW_IP_PROTOCOL_TCP);
end;
finally
// Rele interface
ovPort:=Unassigned;
end;
finally
// Rele interface
ovProfile:=Unassigned;
end;
finally
// Rele interface
ovMgr:=Unassigned;
end;
end;
Espero que Ajude
E.C.S
Gostei + 0
05/02/2007
Eniorm
vc sabe se existe alguma documentação para isso?
abraço
Gostei + 0
05/02/2007
Eniorm
http://www.delphi.eti.br/dicas.php?p=12
abraço
Gostei + 0
05/02/2007
Alexandreb
[b:e85be82438]Primeira:[/b:e85be82438]
{$R *.dfm}
Uses registry;
procedure TForm1.Button1Click(Sender: TObject);
var
Reg:Tregistry;
CtrlSet:string;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
//Pega o ControlSet que esta sendo usado pelo windows
Reg.OpenKey(´SYSTEM\Select´, False);
CtrlSet := FormatFloat(´000´,Reg.ReadInteger(´Current´));
Reg.CloseKey;
//Libera a porta 3050 usada pelo Firebird
Reg.OpenKey(´SYSTEM\ControlSet´ + CtrlSet +´\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\GloballyOpenPorts\List´,
True);
if (not Reg.ValueExists(´3050:TCP´))
then Reg.WriteString(´3050:TCP´,´3050:TCP:*:Enabled:Firebird´);
Reg.CloseKey;
end;
[b:e85be82438]Segunda:[/b:e85be82438]
WinExec(´netsh.exe -c firewall add portopening protocol=TCP port=3050 name=Teste mode=ENABLE scope=SUBNET´, SW_HIDE);
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)