PyWin32 获取网络信息/统计 [英] PyWin32 get network information/statistics

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

问题描述

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

我遵循的步骤:

<块引用>

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

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

现在我面临的问题是在上述两个步骤之后我的下一步应该是什么.我尝试了一些事情,例如:

我从上面生成的 python 文件中复制了 CLSID = IID('{DCB00000-570F-4A9B-8D69-199FDBA5723B}') 行并像使用它一样

<预><代码>>>>导入 win32com>>>obj = win32com.client.gencache.GetClassForCLSID("{DCB00000-570F-4A9B-8D69-199FDBA5723B}")>>>obj.GetConnectivity()回溯(最近一次调用最后一次):文件<交互式输入>",第 1 行,在 <module> 中.类型错误:必须使用 INetworkListManager 实例作为第一个参数调用未绑定的方法 GetConnectivity()(什么都没有)

当我执行 obj.method() 时,它会显示所有可用方法的列表.

所以,现在我不知道该怎么做或如何进行,以及在 pywin32 中使用 Type library 的一般过程是什么.

以上任务只是学习如何使用PyWin32COM MakePy 工具的一部分.

这甚至可以使用 pywin32 实现吗?

解决方案

您需要使用 win32com.client.Dispatch 来实际创建对象.此外,您开始的类是 CoClass,在这种情况下

class NetworkListManager(CoClassBaseClass): # A CoClass

就是你想要的.

win32com.client.Dispatch('{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')

在这里工作.

许多这些 Dispatch 类都有一个人类可读的带点名称作为别名,尽管这个特别的似乎没有.

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.

Now the problem I am facing is after the above two steps what should be my next step. I tried a couple of things like:

I copied the CLSID = IID('{DCB00000-570F-4A9B-8D69-199FDBA5723B}') line from the above generated python file and used it like

>>> import win32com
>>> obj = win32com.client.gencache.GetClassForCLSID("{DCB00000-570F-4A9B-8D69-199FDBA5723B}")
>>> obj.GetConnectivity()
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: unbound method GetConnectivity() must be called with INetworkListManager instance as first argument (got nothing instead)

When I do obj.method() it show a list of all available method.

So, now I have no idea what to do or how to proceed and what is the general process of using Type library with pywin32.

The above task is just a part of learning process on how to use PyWin32,COM MakePy utility.

Is this even achievable using pywin32.?

解决方案

You'll need to use win32com.client.Dispatch to actually create the object. Also, the class you start with is the CoClass, in this case

class NetworkListManager(CoClassBaseClass): # A CoClass

is the one you want.

win32com.client.Dispatch('{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')

works here.

Many of these Dispatch classes have a human readable dotted name as an alias, although this particular one doesn't seem to.

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

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