Criar regra no Firewall do Windows pelo Delphi

Delphi

02/02/2007

Amigos,

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

Eniorm

Curtidas 0

Respostas

Nasguone

Nasguone

02/02/2007

Da uma olhada neste link tem uma base de como vc pode fazer isso!!!

http://www.codeproject.com/w2k/WinXPSP2Firewall.asp


Espero que te ajude
E.C.S


GOSTEI 0
Nasguone

Nasguone

02/02/2007

Se preferir tenta este cód aqui!



// 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
Eniorm

Eniorm

02/02/2007

implementei esse código mas não funcinou...
vc sabe se existe alguma documentação para isso?

abraço


GOSTEI 0
Eniorm

Eniorm

02/02/2007

Opa, achei essa dica que resolve:

http://www.delphi.eti.br/dicas.php?p=12

abraço


GOSTEI 0
Alexandreb

Alexandreb

02/02/2007

vou lhe passar 2 maneiras que são bem faceis:

[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
POSTAR