检测是否启用了防火墙产品

检测是否启用了防火墙产品

如何(从用C#编写的Windows Forms应用程序中)检测是否启用了防火墙产品?

这是我的代码,我在 INetFwMgr上遇到错误,即找不到类型或 namespace

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


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

       INetFwMgr manager = GetFireWallManager();
       bool isFirewallEnabled = manager.LocalPolicy.CurrentProfile.FirewallEnabled;



       private static INetFwMgr GetFireWallManager()
       {
           Type objectType = Type.GetTypeFromCLSID(new Guid(CLSID_FIREWALL_MANAGER));
           return Activator.CreateInstance(objectType) as INetFwMgr;
       }
        private void button1_Click(object sender, EventArgs e)
        {



            if (isFirewallEnabled == false)
           {
                MessageBox.Show("Firewall is not enabled.");
           }
           else
           {
                MessageBox.Show("Firewall is enabled.");
           }

        }
    }
}

最佳答案

NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
bool Firewallenabled = mgr.LocalPolicy.CurrentProfile.FirewallEnabled;

有关详细信息,请参见链接。

http://technet.microsoft.com/en-us/library/cc737845%28WS.10%29.aspx

http://blogs.msdn.com/b/securitytools/archive/2009/08/21/automating-windows-firewall-settings-with-c.aspx

关于c# - 如何检测是否启用了防火墙产品?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13795285/

10-11 04:39