Can I get the firewall's status by c# code? I want to inform the user when his firewall blocked
To get the current status of Windows Firewall using PowerShell, just type Get-NetFirewallProfile in the PowerShell window and press Enter. You'll be shown a list of all the network profiles, whether Windows Firewall is enabled for each profile and information about various other Windows Firewall settings.
You can use the following links to interact with Windows firewall. Include NetFwTypeLib as a reference to your project.
For Window Firewall you can create the manager with the following code:
Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
INetFwMgr manager= (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
from there you can read about the various methods to configure with windows firewall.
Windows Firewall (Windows XP...limited Vista and 7 support) http://msdn.microsoft.com/en-us/library/aa366452(v=VS.85).aspx
Windows Firewall with advanced security (Windows Vista/7)
msdn.microsoft.com/en-us/library/aa366459(v=VS.85).aspx
You can to it via WMI, as any firewall has to report trough WMI its status (it is the way the Security Center shows status).
There's very little information in Internet, these may be starting points:
http://www.mombu.com/microsoft/windows-xp-wmi/t-remotely-get-wmi-info-from-security-center-601256.html
http://msdn2.microsoft.com/en-us/library/ms950397.aspx
The next step is to access WMI classes in C#:
http://www.csharphelp.com/2006/10/wmi-made-easy-for-c/
http://geekswithblogs.net/PsychoCoder/archive/2008/01/25/using_wmi_in_csharp.aspx
...and many others, just google "C# WMI".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With