How to programmatically open the port on Windows OS firewall?

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

After the Windows XP SP2 the Windows firewall service is by default the service which runs on the system startup. By using of the “Windows Firewall” in the control panel it is possible to define the list of so called “exceptions”.

 

This list defines what ports are opened, because all other ports are by default closed. The existing snap-in (double-click on ‘Windows Firewall’) is very easy and intuitive way to control the list of opened ports (“Exceptions”).

 

However you will probably sometimes need to establish the connection with some service on some port which is denied by the firewall. In such cases it would be useful to open the port programmatically, without of need to require an administrator to do that manually.

 

Of course in those cases your application has run in the admin security context. If so, you will have to just create a new string-value in the following registry key to open the port:

 

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\GloballyOpenPorts\List

 

Following values show some self-explanatory examples:

 

Some test TCP port

12345:TCP:*:Enabled:DAMIRTEST

 

Active sync

26675:TCP:169.254.2.0/255.255.255.0:Enabled:ActiveSync Service

 

Damir Dobric

 

Powered by:

www.daenet.de

www.daenet.ba

 


Posted May 31 2006, 11:51 PM by Damir Dobric

Comments

Ahmed Vila wrote re: How to programmatically open the port on Windows OS firewall?
on 06-09-2006 10:56
Great tip, thanks!
greg aiken wrote re: How to programmatically open the port on Windows OS firewall?
on 09-26-2013 16:42

hi damir.  i found your page as i searched for how to programmatically add firewall exceptions on windows.  i am in general familiar with the concept of what a firewall is.  however, both in your page (and others ive found) - there is mention of a 'DomainProfile' exception versus a 'StandardProfile' exception.  can you possibly explain the difference?  both as it relates to what it actually means, and as to how using Microsofts normal Windows Firewall gui - this would be specified using their gui?  perhaps if i can see what the difference is using their tool - it might make some sense to me.  your help would be greatly appreciated.

developers.de is a .Net Community Blog powered by daenet GmbH.