我在下面提到了将我的应用程序添加到Windows防火墙例外列表的代码.我想知道这是否也适用于其他防火墙,例如:防病毒防火墙等.如果没有,请提出解决方案.注意:我的应用程序正在运行管理员权限,但我的用户无法理解快速等等的防火墙设置.我使用Delphi 2007(Win32).
这是我第一次使用这个论坛.请原谅+纠正任何错误.
关心艾伦费尔南德斯
procedure AddApplicationToFirewall(EntryName:string;ApplicationPathAndExe:string);
var
fwMgr,app:OleVariant;
profile:OleVariant;
begin
fwMgr := CreateOLEObject('HNetCfg.FwMgr');
profile := fwMgr.LocalPolicy.CurrentProfile;
app := CreateOLEObject('HNetCfg.FwAuthorizedApplication');
app.ProcessImageFileName := ApplicationPathAndExe;
app.Name := EntryName;
app.Scope := NET_FW_SCOPE_ALL;
app.IpVersion := NET_FW_IP_VERSION_ANY;
app.Enabled :=true;
profile.AuthorizedApplications.Add(app);
end;
Run Code Online (Sandbox Code Playgroud) 我正在使用代码转发端口.此代码在My Windows 7上运行正常; 但我无法在Windows XP上使用它.
问题更新1(2012-10-17 07:32:00Z)
这是我的源代码:
uses
ActiveX, oleAuto;
Procedure AddUPnPEntry(Port: Integer; const Name: ShortString; LAN_IP: string);
Var
Nat: Variant;
Ports: Variant;
SavedCW: Word;
Begin
if NOT(LAN_IP = '127.0.0.1') then
begin
try
Nat := CreateOleObject('HNetCfg.NATUPnP');
Ports := Nat.StaticPortMappingCollection;
// Error Raized From Here!!!
ShowMessage(inttostr(Ports.count));
Ports.Add(Port, 'TCP', Port, LAN_IP, True, name);
except
ShowMessage('An Error occured with adding UPnP Ports. The ' + name +
' port was not added to the router. Please check to see if your ' …Run Code Online (Sandbox Code Playgroud)