I am trying to add application in firewall. It is working fine but it only checks "Public" option. I want to add firewall rule for "Domain".
Here is my code.
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);
}
}
I have followed this link.
Now here in whatever I assign value to Scope, firewall rule is added for public network only. I want to add it for Domain network.
firewallApplication.Scope = NET_FW_SCOPE_.NET_FW_SCOPE_LOCAL_SUBNET;
What I am doing wrong here. I am using Windows 8.