如何檢測(從用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