Search code examples
vb.netcmdwindows-firewallnetsh

In vb.net is there a windows API that shows the same information as "Netsh AdvFirewall Firewall show"


So right now I am trying to see the information that comes out of the following command in to command prompt (cmd):

netsh advfirewall firewall show rule name="TestFirewallUpdateSettings" profile=any

The output I get is:

 Rule Name:                            TestFirewallUpdateSettings

 ----------------------------------------------------------------------
  Enabled:                                 Yes Direction:                  
 In Profiles:                             Domain,Private,Public
 Grouping: LocalIP:                              Any RemoteIP:         
 Any Protocol:                             Any Edge traversal:         
 No Action:                               Allow

What I want is to just read the In Profiles section using vb.net and wondering if there is a API that will do what I am asking for?


Solution

  • Yes, there is. You could go and create your own interop assembly in order to access the objects - INetFwPolicy2 in particular - in the system's COM based FirewallApi.dll. Check this SO thread for details. I did this in the past (Windows 7) and it worked like a charm.

    Also, there is a WMI name space - ROOT\SecurityCenter2 - which is supposed to provide info about firewall amongst other things. However it wasn't well documented and I failed to enumerate it through C# although I can see it through various WMI browser tools.

    You can also check the new Microsoft.TeamFoundation.Build.Common.INetFwPolicy2. It seems to do the same job as the manually created interop assembly.