如果启用了防火墙产品,我如何检测(从用 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.");
}
}
}
}