PyWin32 使用 MakePy 实用程序和 win32com 获取网络统计信息 [英] PyWin32 using MakePy utility and win32com to get Network Statistics

查看:42
本文介绍了PyWin32 使用 MakePy 实用程序和 win32com 获取网络统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是我上一个问题的延续.

我正在尝试使用 PyWin32 为我的 Windows 7 系统获取 Network Statistics.

我遵循的步骤:

<块引用>

1) 运行 COM MakePy 实用程序,然后选择 network list manager 1.0类型库在类型库下.

2) 以上过程生成了这个 python 文件.

接下来我使用

创建了类NetworkListManager(CoClassBaseClass)的对象

将 win32com.client 导入为 wcobj = wc.Dispatch("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")

现在我正在尝试访问上面创建的对象 obj 提供的方法.

help(obj) 给了我

GetNetwork(self, gdNetworkId= )

获取给定网络 ID 的网络.

已连接

返回是否连接到互联网//其他方法删除

所以,现在当我使用

<预><代码>>>>obj.IsConnected真的

效果很好.

现在我面临的问题是如何使用 GetNetowrk 方法,因为当我尝试使用它时

<预><代码>>>>obj.GetNetwork()回溯(最近一次调用最后一次):文件<交互式输入>",第 1 行,在 <module> 中.ret = self._oleobj_.InvokeTypes(2, LCID, 1, (9, 0), ((36, 1),),gdNetworkIdcom_error: (-2147024809, '参数不正确.', None, None)

我还尝试使用 pythoncom.Empty 创建 PyOleEmpty 对象 并将其作为参数传递,但没有成功.

我理解 GetNetwork 需要 NetworkID 作为参数,但方法 GetNetworkId 是在 INetwork 类.

所以我的问题是如何使用使用 MakePy 实用程序 创建的 python 文件中定义的类,这些类不是 CoClass.

解决方案

看起来获取 Network 对象的方法是使用 GetNetworks 枚举它们:

networks=obj.GetNetworks(win32com.client.constants.NLM_ENUM_NETWORK_CONNECTED)对于网络中的网络:打印(network.GetName(),network.GetDescription())

使用网络 ID 会有问题.它们被定义为原始结构,因此需要使用 Records 传递它们.Pywin32 对 IRecordInfo 接口的支持还是有点弱.

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 select network 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.

解决方案

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.

这篇关于PyWin32 使用 MakePy 实用程序和 win32com 获取网络统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆