问题
This question is in continuation to my previous question.
I am trying to get Network Statistics
for my Windows 7
system using PyWin32
.
The steps I followed:
1) Run
COM MakePy utility
and than selectnetwork list manager 1.0 type library
under type library.2) Above process generated this python file.
Next I created the object of class NetworkListManager(CoClassBaseClass)
using
import win32com.client as wc
obj = wc.Dispatch("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")
Now I am trying to access the methods provided by the above created object obj
.
help(obj)
gave me
GetNetwork(self, gdNetworkId= <PyOleEmpty object>
)
Get a network given a Network ID.
IsConnected
Returns whether connected to internet or not
//Other methods removed
So, now when I use
>>> obj.IsConnected
True
It works fine.
Now the problem I am facing is how to use GetNetowrk
method because when I try to use it
>>> obj.GetNetwork()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ret = self._oleobj_.InvokeTypes(2, LCID, 1, (9, 0), ((36, 1),),gdNetworkId
com_error: (-2147024809, 'The parameter is incorrect.', None, None)
I also tried creating PyOleEmpty object
by using pythoncom.Empty
and passed it as a paremeter but no luck.
I understand GetNetwork
require NetworkID
as a parameter but the method GetNetworkId
is defined in INetwork class.
So my question is how to use classes defined in the python file created using MakePy utility
which are not CoClass
.
回答1:
It looks like the way to get to the Network objects is to enumerate them using GetNetworks:
networks=obj.GetNetworks(win32com.client.constants.NLM_ENUM_NETWORK_CONNECTED)
for network in networks:
print (network.GetName(), network.GetDescription())
Using the network ids will be problematic. They're defined as raw structs, so they will need to be passed using Records. Pywin32's support for the IRecordInfo interface is still somewhat weak.
来源:https://stackoverflow.com/questions/9982235/pywin32-using-makepy-utility-and-win32com-to-get-network-statistics