我有一段代码,是根据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上,它只将异常添加为Public,而不是Private,如您在此处用 RED 圈出的那样。
仅设置为Public时,我的程序无法通过FTP连接访问我的主机,从而使我的程序无用。 这个问题只在Windows Vista/7上特别存在;在XP上,当前配置可以正常工作。
如果您有任何线索或有用的指针,请分享。
CreateOleObject
函数内部使用了 CoCreateInstance WinApi 方法,并且所有的错误代码都是使用OleCheck
方法捕获的,所以如果出现任何错误,都会抛出异常。 - RRUZ