You are not logged in.
Pages: 1
On SQLite3UI.pas I have found these procedures:
procedure AddApplicationToXPFirewall(const EntryName, ApplicationPathAndExe: string);
procedure AddPortToXPFirewall(const EntryName: string; PortNumber: cardinal);
I need use them on my application to change firewall settings. I just have fix AddApplicationToXPFirewall to works also with Private profile (in this moment in fact it works only with Public profile - on Windows 7).
Now I need use AddPortToXPFirewall on Windows 7 but I don't know how I need edit it. In fact in this moment it doesn't work.
I need of AddPortToXPFirewall to open 2 ports by my application (both on Private and Pubblic profiles).
Thanks
Offline
This is OK, but AddPortToXPFirewall doesn't work on Windows 7 (as administrator), I need fix it to run as administrator not as user.
Offline
Sounds like if http://msdn.microsoft.com/en-us/library … 8(v=vs.85) is to be taken in account for Seven.
Offline
I wrote this code:
procedure AddPortTo7Firewall(const EntryName: string; PortNumber: cardinal);
var
fwMgr, profile, NewRule, RulesObject: OleVariant;
begin
fwMgr := CreateOleObject('HNetCfg.FwPolicy2');
profile := NET_FW_PROFILE2_PRIVATE OR NET_FW_PROFILE2_PUBLIC;
try
RulesObject := fwMgr.Rules;
NewRule := CreateOleObject('HNetCfg.FWRule');
try
NewRule.Name := EntryName;
NewRule.Description := EntryName;
NewRule.LocalPorts := PortNumber;
NewRule.Protocol := NET_FW_IP_PROTOCOL_TCP;
NewRule.Enabled := TRUE;
NewRule.Profiles := Profile;
NewRule.Action := NET_FW_ACTION_ALLOW;
RulesObject.Add(NewRule);
finally
NewRule := varNull;
RulesObject := varNull;
end;
finally
profile := varNull;
fwMgr := varNull;
end;
end;
I think this is the right way but I get an error on NewRule.LocalPorts, and I don't understand why, Any ideas?
Offline
Did you try to allocate it by application?
See http://stackoverflow.com/questions/9180 … -locations answer.
Offline
Yes, I just see it and AddExceptionToFirewall (of stackoverflow) works well, but with it I can only add application not port. I need open a port.
Any ideas?
Offline
LocalPorts property sounds to be a string (BSTR=WideString).
See http://msdn.microsoft.com/en-us/library … 5).aspx#Y0
Try
NewRule.LocalPorts := IntToStr(PortNumber);
Offline
If I remember correctly I have tried to use an string without success. I'll try again (in this moment I'm not in my office) and I'll let you know.
Offline
I have try it but I get an error on IntToStr(PortNumber); "Parameter is not correct.".
I don't understand why...
Offline
OK I think I have found the problem.
This code works:
procedure AddPortTo7Firewall(const EntryName: string; PortNumber: cardinal);
var
fwMgr, profile, NewRule, RulesObject: OleVariant;
begin
fwMgr := CreateOleObject('HNetCfg.FwPolicy2');
profile := NET_FW_PROFILE2_PRIVATE OR NET_FW_PROFILE2_PUBLIC;
try
RulesObject := fwMgr.Rules;
NewRule := CreateOleObject('HNetCfg.FWRule');
try
NewRule.Name := EntryName;
NewRule.Description := EntryName;
NewRule.Protocol := NET_FW_IP_PROTOCOL_TCP;
NewRule.LocalPorts := PortNumber;
NewRule.Enabled := TRUE;
NewRule.Profiles := Profile;
NewRule.Action := NET_FW_ACTION_ALLOW;
RulesObject.Add(NewRule);
finally
NewRule := varNull;
RulesObject := varNull;
end;
finally
profile := varNull;
fwMgr := varNull;
end;
end;
NOTE: set NewRule.Protocol before NewRule.LocalPorts.
Thanks again.
Offline
I tried to add the Vista/Seven firewall version of these functions to SQLite3UI.pas.
Offline
Any info about if the AddApplicationToFirewall() function works under Windows 8/8.1/10?
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Pages: 1