Return to Snippet

Revision: 47358
at June 6, 2011 22:10 by kashif21

Initial Code
1)first add Refrence of the "hnetcfg.dll" avaialable in the 

2)Then add these references on the code behind

using NATUPNPLib;
using NETCONLib;
using NetFwTypeLib;


3)add these methoods

 private const string CLSID_FIREWALL_MANAGER = "{304CE942-6E39-40D8-943A-B913C40C9CD4}";

  private static NetFwTypeLib.INetFwMgr GetFirewallManager()
            Type objectType = Type.GetTypeFromCLSID(new Guid(CLSID_FIREWALL_MANAGER));
            return Activator.CreateInstance(objectType) as NetFwTypeLib.INetFwMgr;

4)Calling above methood to invoke it on button click.

protected void btnDetectFirewal_Click(object sender, EventArgs e)
            INetFwMgr manager = GetFirewallManager();
            bool isFirewallEnabled = manager.LocalPolicy.CurrentProfile.FirewallEnabled;

            if (isFirewallEnabled == true)
                manager.LocalPolicy.CurrentProfile.FirewallEnabled = false;
                Label1.Text = "Firewall disabled successfully..!";
                manager.LocalPolicy.CurrentProfile.FirewallEnabled = true;
                Label1.Text = "Firewall enabled successfully..!";


Initial URL

Initial Description

Initial Title
Window firewall On and off functionality.

Initial Tags

Initial Language