Hi in this blog I am going to show how Check status of windows firewall using C#.Create a New Project and add Reference to "NetFwTypeLib".
Output:
Download Source Code
Full Source Code:
using NetFwTypeLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FirewallCheck
{
public partial class FirewallStatus : Form
{
private const string firewallid = "";
public FirewallStatus()
{
InitializeComponent();
lblFirewallStatus.Text = "FirewallStatus:"+firewallstatus();
}
public string firewallstatus()
{
INetFwMgr manager = FirewallManager();
bool isFirewallEnabled = manager.LocalPolicy.CurrentProfile.FirewallEnabled;
if (isFirewallEnabled)
return "ON";
else
return "OFF";
}
private static NetFwTypeLib.INetFwMgr FirewallManager()
{
Type objectType = Type.GetTypeFromCLSID(new Guid(firewallid));
return Activator.CreateInstance(objectType) as NetFwTypeLib.INetFwMgr;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FirewallCheck
{
public partial class FirewallStatus : Form
{
private const string firewallid = "";
public FirewallStatus()
{
InitializeComponent();
lblFirewallStatus.Text = "FirewallStatus:"+firewallstatus();
}
public string firewallstatus()
{
INetFwMgr manager = FirewallManager();
bool isFirewallEnabled = manager.LocalPolicy.CurrentProfile.FirewallEnabled;
if (isFirewallEnabled)
return "ON";
else
return "OFF";
}
private static NetFwTypeLib.INetFwMgr FirewallManager()
{
Type objectType = Type.GetTypeFromCLSID(new Guid(firewallid));
return Activator.CreateInstance(objectType) as NetFwTypeLib.INetFwMgr;
}
}
}
Output:
No comments:
Post a Comment