gpt4 book ai didi

Delphi 7 Windows Vista/7 防火墙异常(exception)网络位置

转载 作者:行者123 更新时间:2023-12-03 15:07:50 24 4
gpt4 key购买 nike

我有这段代码,是我根据http://www.activexperts.com/activmonitor/windowsmanagement/scripts/networking/windowsfirewall/找到并实现的。

procedure AddExceptionToFirewall (Caption: String; Executable: String);
var
FirewallMsg: OleVariant;
Application: OleVariant;
CurrentProfile: OleVariant;
begin
FirewallMsg:= CreateOLEObject ('HNetCfg.FwMgr');
CurrentProfile:= FirewallMsg.LocalPolicy.CurrentProfile;
Application:= CreateOLEObject ('HNetCfg.FwAuthorizedApplication');
Application.ProcessImageFileName:= Executable;
Application.Name:= Caption;
Application.Scope:= FW_SCOPE_ALL;
Application.IpVersion:= FW_IP_VERSION_ANY;
Application.Enabled:= True;
CurrentProfile.AuthorizedApplications.Add (Application);
end;

问题是,在 Windows 7 上,它仅将异常(exception)添加为“公共(public)”,而不是“私有(private)”,如您在此处用红色圈出的那样

enter image description here

当设置为仅限公共(public)时,我的程序在通过 FTP 连接访问我的主机时出现问题,从而导致我的程序无用。此问题仅针对 Windows Vista/7;在 XP 上,当前配置运行良好。

如果您有任何线索或有用的指示,请分享。

最佳答案

从 Windows Vista 开始,您必须使用 INetFwPolicy2INetFwRule接口(interface)来访问新的防火墙功能。

尝试此示例,在公共(public)和私有(private)配置文件中添加新规则。

procedure AddExceptionToFirewall(Const Caption, Executable: String);
const
NET_FW_PROFILE2_DOMAIN = 1;
NET_FW_PROFILE2_PRIVATE = 2;
NET_FW_PROFILE2_PUBLIC = 4;

NET_FW_IP_PROTOCOL_TCP = 6;
NET_FW_ACTION_ALLOW = 1;
var
fwPolicy2 : OleVariant;
RulesObject : OleVariant;
Profile : Integer;
NewRule : OleVariant;
begin
Profile := NET_FW_PROFILE2_PRIVATE OR NET_FW_PROFILE2_PUBLIC;
fwPolicy2 := CreateOleObject('HNetCfg.FwPolicy2');
RulesObject := fwPolicy2.Rules;
NewRule := CreateOleObject('HNetCfg.FWRule');
NewRule.Name := Caption;
NewRule.Description := Caption;
NewRule.Applicationname := Executable;
NewRule.Protocol := NET_FW_IP_PROTOCOL_TCP;
NewRule.Enabled := TRUE;
NewRule.Profiles := Profile;
NewRule.Action := NET_FW_ACTION_ALLOW;
RulesObject.Add(NewRule);
end;

关于Delphi 7 Windows Vista/7 防火墙异常(exception)网络位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9180348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com