how to display "Windows Firewall has blocked some features of this program" dialog for my app?

avs099 picture avs099 · May 25, 2012 · Viewed 7.3k times · Source

I'm developing .Net 4.0 C# Windows Forms app which hosts WCF service on some predefined port (let's say 12345). We have another iPad app which talks to this WCF service - and this connection is blocked by windows firewall. My users always have troubles with it because they have to remember to add this app to exception list etc - which causes frustration.

What is required to make Windows to display popup like on the screenshot below for my app, to make it more user-friendly?

UPDATE - I do understand I can programatically update rules in Windows Firewall. However, that would require admin privileges which is not always feasible. For example, I'm thinking about ClickOnce deployments some time in the future - not sure how it will work with this. So I'm still wondering what should I do in order to get that dialog.


SOLUTION: thanks to @alexw answer below, I was able to get the dialog using this simple code:

IPAddress ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 12345);

TcpListener t = new TcpListener(ipLocalEndPoint);
t.Start();
t.Stop();

and more - it's NOT possible to get this popup for WCF service as documentation states (see at the bottom):

Self-hosted HTTP addressing for WCF is not integrated into the Windows firewall. An exception must be added to the firewall configuration to allow inbound connections using a particular URL.

enter image description here

Answer

Alex Wiese picture Alex Wiese · May 27, 2012

I'm not sure what conditions need to be met to expose this dialog, I would assume an application that attempts to open a listening port on a vanilla Windows instance should always display this dialog. Why don't you try adding your application to the 'authorized applications' list, or opening the port manually using the Windows Firewall COM interop (NetFwTypeLib)?

http://blogs.msdn.com/b/securitytools/archive/2009/08/21/automating-windows-firewall-settings-with-c.aspx