[python-win32] Problems with Python+COM and XP Firewall Manager
Robert Olson
olson at mcs.anl.gov
Thu Oct 23 08:56:10 EDT 2003
Hi -
I'm trying to use python+COM to poke at the WinXP firewall configs. I'm
looking at the VBScript sample available here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ics/ics/enabling_internet_connection_firewall_vbscript_.asp
(aka http://snurl.com/qu2 ) and attempting to emulate it in Python. I used
makepy to create a module for the ICS library:
makepy -o hnet.py \windows\system\hnetcfg.dll
I can create the INetSharingManager obj just fine, and invoke its toplevel
methods, but can't use the objects returned from the enumeration.
here's the test code:
import pythoncom
import hnet
n = hnet.NetSharingManager()
print "n=", n
print "sharingInstalled=", n.SharingInstalled
col = n.EnumEveryConnection
print "Col=%s count=%s" % (col, col.Count)
item = col[0]
print "Item is %s type=%s" % (item, type(item))
iidstr = hnet.VTablesNamesToCLSIDMap['INetConnection']
iid = pythoncom.MakeIID(iidstr)
print "iidstr=%s iid=%s" %( iidstr, iid)
try:
item2 = item.QueryInterface(iid)
print "item2=", item2
except Exception, e:
print "QueryInterface failed: ", e
try:
con = n.INetSharingConfigurationForINetConnection(item)
print "con=", con
except Exception, e:
print "INetSharingConfigurationForINetConnection failed: ", e
And here's the output:
C:\temp>python thnet.py
n= <win32com.gen_py.NetCon 1.0 Type Library.NetSharingManager>
sharingInstalled= 1
Col=<win32com.gen_py.NetCon 1.0 Type
Library.INetSharingEveryConnectionCollection> count=2
Item is <PyIUnknown at 0x8cb40c with obj at 0x167408> type=<type 'PyIUnknown'>
iidstr={C08956A1-1CD3-11D1-B1C5-00805FC1270E}
iid={C08956A1-1CD3-11D1-B1C5-00805FC1270E}
QueryInterface failed: There is no interface object registered that
supports this IID
INetSharingConfigurationForINetConnection failed: (-2147467262, 'No such
interface supported', None, None)
I've poked a little at using QueryInterface to turn the item from the
collection into a INetConnection but haven't been able to get that to fly.
I'm using ActiveState Python which doesn't have CastTo; however, I looked
at the source to CastTo in CVS and it looks like it wouldn't work anyway,
as the item in the connection doesn't have __class__ attribute as used by
CastTo.
I find that interface in the registry:
HKEY_CLASSES_ROOT\Interface\{C08956A1-1CD3-11D1-B1C5-00805FC1270E}
Does anyone have any ideas?
thanks,
--bob
More information about the Python-win32
mailing list