如何检测(从用C#编写的Windows Forms应用程序)防火墙产品是否已启用?如何检测防火墙产品是否启用?
这里是我的代码和我得到的错误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.");
}
}
}
}
你是否缺少using指令? – CRoshanLG
是的。如何解决这个问题? –
将命名空间Microsoft.TeamFoundation.Common添加到您的代码中。看到我的答案中的增加。 – CRoshanLG