Wednesday, October 5, 2016

Check Status of Windows Firewall using C#

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".




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;
        }
    }

}

Output:




Download Source Code




No comments:

Post a Comment