免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6085 | 回复: 5
打印 上一主题 下一主题

python wmi使用问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-05-08 11:58 |只看该作者 |倒序浏览
本人没有用过python,但是用过perl

有一个工作要使用wmi来完成,wmi模块安装

code:

import wmi
c = wmi.WMI()
for service in c.Win32_Service(Name="seclogon"):
  result, = service.StopService()
  if result == 0:
    print "Service", service.Name, "stopped"
  else:
    print "Some problem"
  break
else:
  print "Service not found"

但是在编译时,发生错误:

AttributeError: 'module' object has no attribute 'WMI'

论坛徽章:
0
2 [报告]
发表于 2012-05-08 14:32 |只看该作者
好像没有问题吧,解释器提示符下
import wmi
dir(wmi)
看看

论坛徽章:
0
3 [报告]
发表于 2012-05-08 18:40 |只看该作者
回复 2# anonymous0502

>>> import wmi
>>> dir(wmi)
['BASE', 'Dispatch', 'GetObject', 'PROTOCOL', 'ProvideConstants', 'Registry', 'SelfDeprecatingDict', 'WMI', 'WMI_EXCEPTIONS', '_DEBUG', '__VERSION__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_set', '_wmi_class', '_wmi_event', '_wmi_method', '_wmi_namespace', '_wmi_object', '_wmi_property', '_wmi_result', '_wmi_watcher', 'connect', 'connect_server', 'construct_moniker', 'datetime', 'from_1601', 'from_time', 'get_wmi_type', 'handle_com_error', 'obj', 'pywintypes', 're', 'signed_to_unsigned', 'struct', 'sys', 'to_time', 'warnings', 'wbemErrInvalidQuery', 'wbemErrTimedout', 'wbemFlagForwardOnly', 'wbemFlagReturnImmediately', 'x_access_denied', 'x_wmi', 'x_wmi_authentication', 'x_wmi_invalid_query', 'x_wmi_no_namespace', 'x_wmi_timed_out', 'x_wmi_uninitialised_thread']
>>>
这表示什么呢?正常?   

论坛徽章:
0
4 [报告]
发表于 2012-05-08 19:30 |只看该作者
有 'WMI',应该是正常的吧

论坛徽章:
0
5 [报告]
发表于 2012-05-08 22:18 |只看该作者
问题是WMI是个函数吗,你把WMI当函数用了啊,应该是其它的数据属性吧

论坛徽章:
0
6 [报告]
发表于 2012-05-11 18:15 |只看该作者
本帖最后由 happybj20008 于 2012-05-11 23:46 编辑

回复 1# mysqllog


今天第一天开始学习python就遇到这个错误提示,网上找了好久,最后发现我运行这段代码的文件名是wmi.py,wmi库脚本文件重名造成错误,改个名就好了。

PS. Python 3的print语法也变了,要加括号,也耽误了我不少时间
   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP