Solved

Delphi and Windows Firewall Exceptions list

Posted on 2009-05-07
5
1,884 Views
Last Modified: 2013-12-03
Hello,

   How to add my Application Executable to Wndows Firewall Exception list automaticly, so that when my application runs on the machine for the first time it will add itself automaticly to windows firewall exception list without asking the user.

  Windows Automaticly blocks any application trying to use the Internet/LAN connections, and asks the user to Unblock ot Keep Blocking the application from accesing the connection.

  Some Users doesn't understand the message and click on KEPP BLOCKING, so that my application will not do its job.
0
Comment
Question by:i7mad
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:RemkoEB
ID: 24323454
The Jedi Windows Security Library contains a unit for controlling the Windows Firewall.
See http://blog.delphi-jedi.net/security-library/ and http://jwscldoc.delphi-jedi.net/index.html?frmname=topic&frmfile=JwsclFirewall_pas.html

I think you can use procedure AddToWinFirewall(ApplicationFilename: TJwString; NameOnExeptionlist: TJwString; EnableRule: Boolean);

0
 

Author Comment

by:i7mad
ID: 24323510
I think it is easier than using Outside laibraries.
   Some API functions should solve the story.
0
 

Author Comment

by:i7mad
ID: 24323524
libraries

sorry typo
0
 
LVL 3

Accepted Solution

by:
RemkoEB earned 500 total points
ID: 24323536
Then you need to import the typelib (from %windir%\system32\hnetcfg.dll ) and implement yourself.
Documentation of the interfaces is here: http://msdn.microsoft.com/en-us/library/aa366452(VS.85).aspx
0
 

Author Comment

by:i7mad
ID: 24372112
I found this and it's worked :
uses ActiveX, ComObj;
 

const

   NET_FW_PROFILE_DOMAIN = 0;

   NET_FW_PROFILE_STANDARD = 1;

   NET_FW_IP_VERSION_ANY = 2;

   NET_FW_IP_PROTOCOL_UDP = 17;

   NET_FW_IP_PROTOCOL_TCP = 6;

   NET_FW_SCOPE_ALL = 0;

   NET_FW_SCOPE_LOCAL_SUBNET = 1;

 
 

procedure AddPortToFirewall(EntryName:string;PortNumber:Cardinal);

var

  fwMgr,port:OleVariant;

  profile:OleVariant;

begin

  fwMgr := CreateOLEObject('HNetCfg.FwMgr');

  profile := fwMgr.LocalPolicy.CurrentProfile;

  port := CreateOLEObject('HNetCfg.FWOpenPort');

  port.Name := EntryName;

  port.Protocol := NET_FW_IP_PROTOCOL_TCP;

  port.Port := PortNumber;

  port.Scope := NET_FW_SCOPE_ALL;

  port.Enabled := true;

  profile.GloballyOpenPorts.Add(port);

end;
 

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;

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2015 locks debug executable 9 134
QRReport  TQrmemo vertical stretching 1 42
Delphi IDE crash without error message ... 7 75
Question to Pivot table 1 34
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now