Reputation: 314
Recently in trying to access the properties and methods of the windows firewall in vba I referenced hnetcfg.dll
and was able to dimension variables for objects like inetfwMGr
, inetfwPolicy
etc.
But I couldn't create objects for them as required e.g.
set obj = new inetfwmgr
wouldn't work
Reading around I learned I needed to use
CreateObject("hnetcfg.FwMgr")
to progress any further.
What I want to know is how one can learn which objects can be created from a given dll in VBA. looking at the reference here. I can't find a single clue to indicate that you need to create an object hnetcfg.FwMgr
to be able to proceed. Why FwMgr
? How can I discover if there are other objects that be created from hnetgfg.dll
? Is this information supposed to be a in a reference I haven't seen or is implicit from some looking at the properties of hnetcfg
?
Any insight would be appreciated.Thanks
Upvotes: 4
Views: 2185
Reputation: 27488
I don't know anything about this dll, but I think this will help.
You can use CreateObject, and you may want to in the long run for increased portability. This is called "late binding." On the other hand, if you've set the reference to the dll, you can then dimension and create new NetFwLibLib objects ("early binding"). The advantage here is that you'll get intellisense and can examine its properties in the object browser. Here's some code written in the Excel VBE:
Sub test()
Dim test As NetFwTypeLib.INetFwMgr
Set test = New NetFwTypeLib.INetFwMgr
With test
.CurrentProfileType = ...
End With
End Sub
In addition you can use the Object Browser to examine FwTypeLib. Just click F2 (in Excel's VBE in this case) and you'll see something like this:
Upvotes: 5
Reputation: 4816
You need to use a type library viewer. I strongly recommend TLViewer.
iTripoli also has a decent one.
There are also plenty of scripting references for Windows Firewall.
Windows Firewall Tools and Settings Scripting Reference
Windows Firewall Scripting (ActiveXperts)
Upvotes: 2