gpt4 book ai didi

c# - 如何检测是否启用了防火墙产品?

转载 作者:可可西里 更新时间:2023-11-01 13:08:45 26 4
gpt4 key购买 nike

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

这是我的代码,我在 INetFwMgr that type or namespace could not found 上遇到错误

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com