// WIN 7 WFP // #include "stdafx.h" #include <netfw.h> int _tmain(int argc, _TCHAR* argv[]) { typedef BOOL (*RuleCallback)(fw::INetFwRulePtr& Rule); void ListRules(RuleCallback Callback); { HRESULT hr; // Connect to the firewall fw::INetFwPolicy2Ptr Pol2; hr = Pol2.CreateInstance(__uuidof(fw::NetFwPolicy2)); if(Pol2 == NULL) return; // Retrieve collection rules fw::INetFwRulesPtr Rules = Pol2->Rules; if(Rules == NULL) return; // enumerate the collection and call a callback function ULONG num; VARIANT obj; IEnumVARIANTPtr enumerator = Rules->Get_NewEnum(); while(enumerator->Next(1, &obj, &num) == S_OK) { fw::INetFwRulePtr Rule = obj; if(!Callback(Rule)) return; } } return 0; } </netfw.h>
#import
Ptr
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)