XP防火墙规则

前端之家收集整理的这篇文章主要介绍了XP防火墙规则前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何以编程方式在 Windows XP上将应用程序或端口添加到Windows防火墙?
尝试从我们的开源 SQlite3UI.pas单元中提取代码
  1. function GetXPFirewall(var fwMgr,profile: OleVariant): boolean;
  2. begin
  3. Result := (Win32Platform=VER_PLATFORM_WIN32_NT) and
  4. (Win32MajorVersion>5) or ((Win32MajorVersion=5) and (Win32MinorVersion>0));
  5. if result then // need Windows XP at least
  6. try
  7. fwMgr := CreateOleObject('HNetCfg.FwMgr');
  8. profile := fwMgr.LocalPolicy.CurrentProfile;
  9. except
  10. on E: Exception do
  11. result := false;
  12. end;
  13. end;
  14.  
  15. const
  16. NET_FW_PROFILE_DOMAIN = 0;
  17. NET_FW_PROFILE_STANDARD = 1;
  18. NET_FW_IP_VERSION_ANY = 2;
  19. NET_FW_IP_PROTOCOL_UDP = 17;
  20. NET_FW_IP_PROTOCOL_TCP = 6;
  21. NET_FW_SCOPE_ALL = 0;
  22. NET_FW_SCOPE_LOCAL_SUBNET = 1;
  23.  
  24. procedure AddApplicationToXPFirewall(const EntryName,ApplicationPathAndExe: string);
  25. var fwMgr,profile,app: OleVariant;
  26. begin
  27. if GetXPFirewall(fwMgr,profile) then
  28. try
  29. if profile.FirewallEnabled then begin
  30. app := CreateOLEObject('HNetCfg.FwAuthorizedApplication');
  31. try
  32. app.ProcessImageFileName := ApplicationPathAndExe;
  33. app.Name := EntryName;
  34. app.Scope := NET_FW_SCOPE_ALL;
  35. app.IpVersion := NET_FW_IP_VERSION_ANY;
  36. app.Enabled :=true;
  37. profile.AuthorizedApplications.Add(app);
  38. finally
  39. app := varNull;
  40. end;
  41. end;
  42. finally
  43. profile := varNull;
  44. fwMgr := varNull;
  45. end;
  46. end;
  47.  
  48. procedure AddPortToXPFirewall(const EntryName: string; PortNumber: cardinal);
  49. var fwMgr,port: OleVariant;
  50. begin
  51. if GetXPFirewall(fwMgr,profile) then
  52. try
  53. if profile.FirewallEnabled then begin
  54. port := CreateOLEObject('HNetCfg.FWOpenPort');
  55. port.Name := EntryName;
  56. port.Protocol := NET_FW_IP_PROTOCOL_TCP;
  57. port.Port := PortNumber;
  58. port.Scope := NET_FW_SCOPE_ALL;
  59. port.Enabled := true;
  60. profile.GloballyOpenPorts.Add(port);
  61. end;
  62. finally
  63. port := varNull;
  64. profile := varNull;
  65. fwMgr := varNull;
  66. end;
  67. end;

它将允许您将应用程序或端口添加到XP防火墙.应该从德尔福6到XE工作.

猜你在找的Windows相关文章