Unable to set INetFWRule Interfaces property

  • Thread starter Thread starter Anant
  • Start date Start date
A

Anant

Hi,
Apologies if this is not the correct place to post this message.

I want to set firewall rule programmatically on just one Network Interface
card identified by its Guid.

I have the valid guid and i want to assign it to Interfaces property, I
don't get compilation error but during run time i get "Value does not fall
within the expected range."

Here's a piece of my code snippet.

INetFwRule NewFwRule = null;
Type typeFWRule = Type.GetTypeFromProgID("HNetCfg.FWRule");
NewFwRule = (INetFwRule)Activator.CreateInstance(typeFWRule);
Guid = {<<valid Guid of my wireless card>>}
if (NewFwRule != null)
{
NewFwRule.Name = ruleName;
NewFwRule.Description = ruleDesc;
NewFwRule.ApplicationName = applnName;
//NewFwRule.serviceName ="AthHostService";
NewFwRule.Protocol = protocol;
NewFwRule.LocalPorts = localPorts;
NewFwRule.Grouping = ruleGrouping;
NewFwRule.Profiles = CurrentProfilesBitMask;
NewFwRule.Action =
NetFwTypeLib.NET_FW_ACTION_.NET_FW_ACTION_ALLOW;
NewFwRule.Enabled = true;
NewFwRule.InterfaceTypes = "Wireless";
NewFwRule.Interfaces = Guid;//<<<----Exception comes here

//Add the Firewall Rule
if (fwPolicy2 != null)
{
fwPolicy2.Rules.Add(NewFwRule);
}
}

Can anyone pls point out what is the mistake i am doing. Any help will be
greatly appreciated.

Thanks
 
Back
Top