I'm starting to mess around with the Windows Firewall with Advanced Security API in Vista, located at : http://msdn.microsoft.com/en-us/library ... S.85).aspx
I'm adding an application rule by converting the code here : http://msdn.microsoft.com/en-us/library ... S.85).aspx
Here is the code I have so far:
Code: Select all
Enumeration ;NET_FW_PROFILE_TYPE2
#NET_FW_PROFILE2_DOMAIN = $0001
#NET_FW_PROFILE2_PRIVATE = $0002
#NET_FW_PROFILE2_PUBLIC = $0004
#NET_FW_PROFILE2_ALL = $7FFFFFFF
EndEnumeration
Enumeration ;NET_FW_ACTION
#NET_FW_ACTION_BLOCK
#NET_FW_ACTION_ALLOW
#NET_FW_ACTION_MAX
EndEnumeration
#NET_FW_IP_PROTOCOL_TCP = 6
Interface INetFwPolicy2 Extends IDispatch
get_BlockAllInboundTraffic(x)
put_BlockAllInboundTraffic(x)
get_CurrentProfileTypes(x)
get_DefaultInboundAction(x)
put_DefaultInboundAction(x)
get_DefaultOutboundAction(x, y)
put_DefaultOutboundAction(x, y)
get_ExcludedInterfaces(x)
put_ExcludedInterfaces(x)
get_FirewallEnabled(x)
put_FirewallEnabled(x)
get_IsRuleGroupCurrentlyEnabled(x, y)
get_IsRuleGroupEnabled(x, y, z)
get_LocalPolicyModifyState(x)
get_NotificationsDisabled(x)
put_NotificationsDisabled(x)
get_Rules(x)
get_ServiceRestriction(x)
get_UnicastResponsesToMulticastBroadcastDisabled(x)
put_UnicastResponsesToMulticastBroadcastDisabled(x)
EndInterface
Interface INetFwRule Extends IDispatch
get_Action(x)
put_Action(x)
get_Name(x)
put_Name(x.s)
get_Description(x)
put_Description(x.s)
get_ApplicationName(x)
put_ApplicationName(x.s)
get_ServiceName(x)
put_ServiceName(x)
get_Protocol(x)
put_Protocol(x)
get_LocalPorts(x)
put_LocalPorts(x.s)
get_RemotePorts(x)
put_RemotePorts(x)
get_LocalAddresses(x)
put_LocalAddresses(x)
get_RemoteAddresses(x)
put_RemoteAddresses(x)
get_IcmpTypesAndCodes(x)
put_IcmpTypesAndCodes(x)
get_Direction(x)
put_Direction(x)
get_Interfaces(x)
put_Interfaces(x)
get_InterfaceType(x)
put_InterfaceTypes(x)
get_Enabled(x)
put_Enabled(x)
get_Grouping(x)
put_Grouping(x.s)
get_Profiles(x)
put_Profiles(x)
get_EdgeTraversal(x)
put_EdgeTraversal(x)
EndInterface
Interface INetFwRules Extends IDispatch
get_Count(a)
Add(a)
Remove(a)
Item(a,b)
get__NewEnum(a)
EndInterface
CoInitialize_(0)
If CoCreateInstance_(?CLSID_NetFwPolicy2,0,1,?IID_INetFwPolicy2,@fwPolicy2_obj.INetFwPolicy2) = 0
fwPolicy2_obj\get_Rules(@RulesObject.INetFwRules)
fwPolicy2_obj\get_CurrentProfileTypes(@CurrentProfile.INetFwPolicy2)
If CoCreateInstance_(?CLSID_NetFwRule,0,1,?IID_INetFwRule,@NewRule_obj.INetFwRule)
NewRule_obj\put_Name("My Application Name")
NewRule_obj\put_Description("Allow my application network traffic")
NewRule_obj\put_ApplicationName("%systemDrive%\\Program Files\\MyApplication.exe")
NewRule_obj\put_Protocol(#NET_FW_IP_PROTOCOL_TCP)
NewRule_obj\put_LocalPorts("4000")
NewRule_obj\put_Enabled(#VARIANT_FALSE)
NewRule_obj\put_Grouping("@firewallapi.dll,-23255")
NewRule_obj\put_Profiles(CurrentProfile)
NewRule_obj\put_Action(#NET_FW_ACTION_MAX)
EndIf
;Add a new rule
RulesObject\add(NewRule_obj)
EndIf
CoUninitialize_()
DataSection
CLSID_NetFwPolicy2:
Data.l $E2B3C97F
Data.w $6AE1,$41AC
Data.b $81,$7A,$F6,$F9,$21,$66,$D7,$DD
IID_INetFwPolicy2:
Data.l $98325047
Data.w $C671,$4174
Data.b $8D,$81,$DE,$FC,$D3,$F0,$31,$86
CLSID_NetFwRule:
Data.l $2C5BC43E
Data.w $3369, $4C33
Data.b $AB,$0C,$BE,$94,$69,$67,$7A,$F4
IID_INetFwRule:
Data.l $AF230D27
Data.w $BABA,$4E42
Data.b $AC,$ED,$F5,$24,$F2,$2C,$FC,$E2
IID_INetFwRules:
Data.l $9C4C6277
Data.w $5027, $441E
Data.b $AF,$AE,$CA,$1F,$54,$2D,$A0,$09
EndDataSection
Code: Select all
RulesObject\add(NewRule_obj)
I can't seem to get rid of the error, what am I doing wrong? Any help appreciated.
Thank You.


