win32com(VBScript to Python)问题 [英] win32com (VBScript to Python) problem

查看:54
本文介绍了win32com(VBScript to Python)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我(非常专家)试图使用一段VBScript(关闭

Windows工作站)转换为Python但是已经遇到了问题。

下面的VBScript工作正常;

pc =" MyPC"


设置oWMI = GetObject( winmgmts:{impersonationLevel = imper sonate,(Shutdown)}!\\_

& pc&" \root \ cimv2")


设置colOperatingSystems = oWMI.ExecQuery(" Select * from Win32_OperatingSystem")


For colOperatingSystems中的每个obj

obj.Win32shutdown 12

下一页


但我的翻译结果是'''int''对象不可调用'使用

尝试调用Win32Shutdown。


这是使用Python 2.3.2 win32all 1.57或Active Python 2.3.2


打印类型(obj.Win32ShutDown)

给int


打印obj.Win32ShutDown

给出87 - ASCII代码W - 巧合的是?


导入win32com.client,sys

pc =''MyPC''


oWMI =

win32com.client.GetObject(rwinmgmts:{impersonatio nLevel = impersonate,\

(Shutdown)}!\\+ pc + r" \root \ cimv2")

colOperatingSystems = oWMI.ExecQuery(r" Select * from Win32_OperatingSystem")


对于colOperatingSystems中的obj:

obj.Win32ShutDown(12)


-

___

| im ---- ARM Powered ----



I''m (very non expert) trying to use a snippet of VBScript (to shut down
Windows workstations) converted to Python but have hit a problem.
The VBScript below work fine;
pc="MyPC"

Set oWMI=GetObject("winmgmts:{impersonationLevel=imper sonate,(Shutdown)}!\\"_
& pc & "\root\cimv2")

Set colOperatingSystems = oWMI.ExecQuery("Select * from Win32_OperatingSystem")

For Each obj in colOperatingSystems
obj.Win32shutdown 12
Next

but my translation results in "''int'' object is not callable" with the
attempted call to Win32Shutdown.

This is with Python 2.3.2 win32all 1.57 or Active Python 2.3.2

print type(obj.Win32ShutDown)
gives int

print obj.Win32ShutDown
gives 87 - the ASCII code of "W" - coincidentally ?


import win32com.client, sys
pc=''MyPC''

oWMI =
win32com.client.GetObject(r"winmgmts:{impersonatio nLevel=impersonate,\
(Shutdown)}!\\" + pc + r"\root\cimv2")

colOperatingSystems = oWMI.ExecQuery(r"Select * from Win32_OperatingSystem")

for obj in colOperatingSystems:
obj.Win32ShutDown(12)


--
___
|im ---- ARM Powered ----

推荐答案

不知道你想要做什么,只是一个问题。


为什么要使用COM,关闭是一个exe,为什么不执行呢?


Rony

" Tim Howarth < ti*@worthy.demon.co.uk> aécritdansle message de news:
d715dc564c.ti*@worthy.demon.co.uk 。 ..
Not knowing exactly what you want to do, just a question.

Why use COM, shutdown is an exe so why not just execute it?

Rony
"Tim Howarth" <ti*@worthy.demon.co.uk> a écrit dans le message de news:
d715dc564c.ti*@worthy.demon.co.uk...


我(非常非专家)试图使用一段VBScript(关闭Windows工作站)转换为Python但是遇到问题。

下面的VBScript工作正常;

pc =" MyPC"

设置
oWMI = GetObject(& ; winmgmts:{impersonationLevel = imper sonate,(Shutdown)}!\\" _& pc&" \root \ cimv2")

设置colOperatingSystems = oWMI.ExecQuery (选择*来自
Win32_OperatingSystem)
对于colOperatingSystems中的每个obj
obj.Win32shutdown 12


但我的翻译结果为 ''int''对象不可调用'尝试调用Win32Shutdown。

这是使用Python 2.3.2 win32all 1.57或Active Python 2.3.2

打印类型(obj.Win32ShutDown)
给出了

print obj.Win32ShutDown
给出了87 - ASCII码W。 - 巧合的是?

导入win32com.client,sys

pc =''MyPC''

oWMI =
win32com.client.GetObject(rwinmgmts:{impersonatio nLevel = impersonate,\
(Shutdown)}!\\" + pc + r" \root \ cimv2")

colOperatingSystems = oWMI.ExecQuery(r" Select * from
Win32_OperatingSystem")
for coljperatingSystems:
obj.Win32ShutDown(12)


-
___
| im ---- ARM Powered ----


I''m (very non expert) trying to use a snippet of VBScript (to shut down
Windows workstations) converted to Python but have hit a problem.
The VBScript below work fine;
pc="MyPC"

Set oWMI=GetObject("winmgmts:{impersonationLevel=imper sonate,(Shutdown)}!\\"_ & pc & "\root\cimv2")

Set colOperatingSystems = oWMI.ExecQuery("Select * from Win32_OperatingSystem")
For Each obj in colOperatingSystems
obj.Win32shutdown 12
Next

but my translation results in "''int'' object is not callable" with the
attempted call to Win32Shutdown.

This is with Python 2.3.2 win32all 1.57 or Active Python 2.3.2

print type(obj.Win32ShutDown)
gives int

print obj.Win32ShutDown
gives 87 - the ASCII code of "W" - coincidentally ?


import win32com.client, sys
pc=''MyPC''

oWMI =
win32com.client.GetObject(r"winmgmts:{impersonatio nLevel=impersonate,\
(Shutdown)}!\\" + pc + r"\root\cimv2")

colOperatingSystems = oWMI.ExecQuery(r"Select * from Win32_OperatingSystem")
for obj in colOperatingSystems:
obj.Win32ShutDown(12)


--
___
|im ---- ARM Powered ----



在消息< bp **********@news-reader4.wanadoo.fr>

" Rony Steelandt" < BU **** @ wanadoo.fr>写道:
In message <bp**********@news-reader4.wanadoo.fr>
"Rony Steelandt" <bu****@wanadoo.fr> wrote:
不知道你想要做什么,只是一个问题。

为什么要使用COM,shutdown是一个exe,为什么不执行呢?
Not knowing exactly what you want to do, just a question.

Why use COM, shutdown is an exe so why not just execute it?




使用这种方法可以关闭和关闭(12值)一台

机器,来自reskit的shutdown.exe离开机器你现在可以

关闭。

我想用它来关闭我在学校里工作的所有机器服务器上的日程安排。


我可以使用VBscript版本但是如果关闭机器

会有很长的延迟 - 在Python中我可以使用与单个机器进行通信(为了在VBScript中实现这一点,我必须为每台机器调用一个新的
w(c)脚本实例),有效地关闭它们
平行下来。


-

___

| im ---- ARM Powered - -



Using this method you can shutdown and poweroff (the 12 value) a
machine, shutdown.exe from the reskit leaves a machine at "You may now
switch off".
I want to use this to shutdown all machines in the school in which I
work from a schedule on a server.

I could use the VBscript version but there are long delays if a machine
is switched off - in Python I can thread the communication with
individual machines (to achieve this in VBScript I have to call a new
instance of w(c)script for each machine), effectively shutting them
down in parallel.

--
___
|im ---- ARM Powered ----


嗨!


此代码重新启动计算机''CPU01''(如果权利没问题):

import win32com.client

WMIService =

win32com.client.GetObject( r" winmgmts:{impersonatio nLevel = impersonate,(Shutdo

wn)}!\\CPU01 \root \ cimv2")


objs = WMIService.ExecQuery(r" Select * from Win32_OperatingSystem")

for obj in objs:

obj.Reboot()


>
也许这个样本可以帮到你?


@ -salutations

-

Michel Claveau $ b $bmél: http://cerbermail.com/?6J1TthIa8B

网站: http://mclaveau.com

NG: news://news.zoo-logique.org/programmation.Paradox
Hi !

This code "reboot" the computer ''CPU01'' (if rights are OK) :
import win32com.client
WMIService =
win32com.client.GetObject(r"winmgmts:{impersonatio nLevel=impersonate,(Shutdo
wn)}!\\CPU01\root\cimv2")

objs = WMIService.ExecQuery(r"Select * from Win32_OperatingSystem")
for obj in objs:
obj.Reboot()


Perhaps this sample can help you ?

@-salutations
--
Michel Claveau
mél : http://cerbermail.com/?6J1TthIa8B
site : http://mclaveau.com
NG : news://news.zoo-logique.org/programmation.Paradox


这篇关于win32com(VBScript to Python)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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