Advertisement
Guest User

Firewall exception

a guest
Jun 28th, 2014
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.03 KB | None | 0 0
  1. const
  2.  NET_FW_SCOPE_ALL = 0;
  3.  NET_FW_IP_VERSION_ANY = 2;
  4.  
  5. procedure SetFirewallException(AppName, FileName:string);
  6. var
  7.  FirewallObject: Variant;
  8.  FirewallManager: Variant;
  9.  FirewallProfile: Variant;
  10. begin
  11.  try
  12.   FirewallObject := CreateOleObject('HNetCfg.FwAuthorizedApplication');
  13.   FirewallObject.ProcessImageFileName := FileName;
  14.   FirewallObject.Name := AppName;
  15.   FirewallObject.Scope := NET_FW_SCOPE_ALL;
  16.   FirewallObject.IpVersion := NET_FW_IP_VERSION_ANY;
  17.   FirewallObject.Enabled := True;
  18.   FirewallManager := CreateOleObject('HNetCfg.FwMgr');
  19.   FirewallProfile := FirewallManager.LocalPolicy.CurrentProfile;
  20.   FirewallProfile.AuthorizedApplications.Add(FirewallObject);
  21.  except
  22.  end;
  23. end;
  24.  
  25. procedure RemoveFirewallException(FileName: string);
  26. var
  27.  FirewallManager: Variant;
  28.  FirewallProfile: Variant;
  29. begin
  30.  try
  31.   FirewallManager := CreateOleObject('HNetCfg.FwMgr');
  32.   FirewallProfile := FirewallManager.LocalPolicy.CurrentProfile;
  33.   FirewallProfile.AuthorizedApplications.Remove(FileName);
  34.  except
  35.  end;
  36. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement