我正在尝试在防火墙中添加应用程序。它工作正常,但它只检查“公共”选项。我想为“域”添加防火墙规则。
这是我的代码。
private const string ClsidFirewallManager = "{304CE942-6E39-40D8-943A-B913C40C9CD4}";
private INetFwMgr _firewallManager;
private INetFwMgr FirewallMgr
{
get { return _firewallManager ?? (_firewallManager = (INetFwMgr)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(ClsidFirewallManager)))); }
}
private INetFwPolicy FirewallPolicy
{
get { return FirewallMgr.LocalPolicy; }
}
private INetFwProfile _firewallProfile;
private INetFwProfile FirewallProfile
{
get { return _firewallProfile ?? (_firewallProfile = FirewallPolicy.CurrentProfile); }
}
public void AddApplication(string imageFileName, string registerName)
{
if (!IsAppEnabled(imageFileName))
{
var firewallApplicatoins = FirewallProfile.AuthorizedApplications;
var type = Type.GetTypeFromProgID("HNetCfg.FwAuthorizedApplication");
var firewallApplication = Activator.CreateInstance(type) as INetFwAuthorizedApplication;
firewallApplication.ProcessImageFileName = imageFileName;
firewallApplication.Name = registerName;
firewallApplication.Scope = NET_FW_SCOPE_.NET_FW_SCOPE_LOCAL_SUBNET; ---> Here it adds to public, whatever the value for enum is.
firewallApplication.Enabled = true;
firewallApplicatoins.Add(firewallApplication);
}
}
我已经关注了这个链接。
现在,无论我为 Scope 分配什么值,都只为公共网络添加防火墙规则。我想为域网络添加它。
firewallApplication.Scope = NET_FW_SCOPE_.NET_FW_SCOPE_LOCAL_SUBNET;
我在这里做错了什么。我正在使用 Windows 8。