小编Pav*_*kat的帖子

如何检测防火墙产品是否已启用?

如何启用防火墙产品,如何检测(从使用C#编写的Windows窗体应用程序)?

这是我的代码,我在INetFwMgr上遇到错误,无法找到类型或命名空间

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.");
           }

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# windows-firewall windows-firewall-api windows-applications

7
推荐指数
1
解决办法
5759
查看次数