/ Published in: C#

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
1)first add Refrence of the "hnetcfg.dll" avaialable in the "C:\Windows\System32" 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() { 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..!"; } else { manager.LocalPolicy.CurrentProfile.FirewallEnabled = true; Label1.Text = "Firewall enabled successfully..!"; } }
Comments
