Search code examples
c#windows-firewall-api

Get the authorized application list through firewall


In my application, I broadcast events over the network with standard messages for other application instances, in order to synchronize.

I want to add my app to the authorized list of the firewall, and I do this with:

NetFwTypeLib API DLL

If I do this in every run, it will be added to the list several times.

My question is: How can I retrieve the list of authorized applications for checking if the application was added before, and then not add it to the list?


Solution

  • Based on your comments, it sounds like you want something like this:

      Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false); 
      INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType); 
      applications = 
        (INetFwAuthorizedApplications)mgr.LocalPolicy.CurrentProfile.AuthorizedApplications;
    

    For older OS's, look here for complete documentation:

    For newer OS's (Vista and higher), use Windows Firewall with Advanced Security instead.