473,411 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

win32com (VBScript to Python) problem



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 ----
Jul 18 '05 #1
13 5380
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...


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 ----

Jul 18 '05 #2
In message <bp**********@news-reader4.wanadoo.fr>
"Rony Steelandt" <bu****@wanadoo.fr> wrote:
Not knowing exactly what you want to do, just a question.

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


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 ----
Jul 18 '05 #3
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
Jul 18 '05 #4
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

Jul 18 '05 #5
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
site : http://mclaveau.com

Jul 18 '05 #6
Tim Howarth <ti*@worthy.demon.co.uk> wrote in
news:6e24de564c.ti*@worthy.demon.co.uk:
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.


This isn't a Python solution at all, but have you looked at PsTools
(http://www.sysinternals.com)? It includes a command to remotely shutdown a
machine including options to specify whether to log the user off, poweroff,
reboot, hibernate etc. There is also a timeout so you can give users a
chance to save their work (it displays a popup on their screen telling them
the system is shutting down). You could just spawn a bunch of psshutdown
processes off in parallel. It is free, although you cannot further
redistribute it.

PsTools also includes other programs which could be useful in a classroom
environment (useful for teachers, devastating if the pupils get their hands
on them and you don't have security set up right).

--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #7
Sorry for the multi-post, my FAI is too much lazy...

Jul 18 '05 #8
In message <Xn***************************@127.0.0.1>
Duncan Booth <du****@NOSPAMrcp.co.uk> wrote:
Tim Howarth <ti*@worthy.demon.co.uk> wrote in
news:6e24de564c.ti*@worthy.demon.co.uk:
I want to use this to shutdown all machines in the school in which I
work from a schedule on a server.


This isn't a Python solution at all, but have you looked at PsTools
(http://www.sysinternals.com)?


Yes, very handy tools.

It's just that I'd like to do the shutting down myself - why call
pshutdown if I can call the shut down mechanism directly.
--
___
|im ---- ARM Powered ----
Jul 18 '05 #9
In message <bp**********@news-reader2.wanadoo.fr>
"Michel Claveau" <No********@No.Spam.mclaveau.No.Spam.com> wrote:
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()


This gives me the same error 'int' is not callable.

Maybe it's something to do with late/early binding ??

What version of Python/win32all have you used this on ?

--
___
|im ---- ARM Powered ----
Jul 18 '05 #10
Tim Howarth <ti*@worthy.demon.co.uk> wrote in
news:4700e5564c.ti*@worthy.demon.co.uk:
In message <Xn***************************@127.0.0.1>
Duncan Booth <du****@NOSPAMrcp.co.uk> wrote:
Tim Howarth <ti*@worthy.demon.co.uk> wrote in
news:6e24de564c.ti*@worthy.demon.co.uk:
> I want to use this to shutdown all machines in the school in which I
> work from a schedule on a server.


This isn't a Python solution at all, but have you looked at PsTools
(http://www.sysinternals.com)?


Yes, very handy tools.

It's just that I'd like to do the shutting down myself - why call
pshutdown if I can call the shut down mechanism directly.

I would say because with the pstools version you get a message on screen
telling the user that their system is going to shut down in 1 minute (or
whatever) and giving them an opportunity to save their work. You might
never need that, but it could save someone a lot of grief.
--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #11
In message <Xn***************************@127.0.0.1>
Duncan Booth <du****@NOSPAMrcp.co.uk> wrote:
It's just that I'd like to do the shutting down myself - why call
pshutdown if I can call the shut down mechanism directly.

I would say because with the pstools version you get a message on screen
telling the user that their system is going to shut down in 1 minute (or
whatever) and giving them an opportunity to save their work. You might
never need that,


Indeed, for this task I just want to shutdown whatever's left switched
on of 300+ PCs, at (say) 10:00pm.
--
___
|im ---- ARM Powered ----
Jul 18 '05 #12
Just a comment: is shutdown.exe leaves the machine in the "you can switch
off", try shutdown -s, it does the job for me.

M.
Jul 18 '05 #13
In message <bp**********@sunnews.cern.ch>
"Matteo Risoldi" <Ma************@cern.ch> wrote:
Just a comment: is shutdown.exe leaves the machine in the "you can switch
off", try shutdown -s, it does the job for me.


Ah, I'm guessing that that is an XP addition, the version of
shutdown.exe that I have (from Win2k reskit IIRC) doesn't undertsand
that switch.
--
___
|im ---- ARM Powered ----
Jul 18 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Stockton | last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and I'm running into an issue importing the win32com.client module. Before installing the new version, I made sure to properly...
3
by: RJ | last post by:
Hi, I've been going over the Quick Start to Client side COM and Python and many other sources, but cannot find an example that will get my com/ActiveX .ocx USB device driver imported. The Excel...
1
by: Cristian Hasbun from Chile | last post by:
I need a win32com guru please... i'm not python expert, but i understand mi trouble... Requirements: Hook EyesWeb 3.2.0 (http://www.eyesweb.org) COM Module with Python 2.0.1 i used win32com...
3
by: allanc | last post by:
i have a python module that i've registered as a com server. i also have a vbscript that i use to test the com server. i have a loop that creates an instance of the com server on each iteration....
1
by: Patrick | last post by:
I am investigating a web-based app wherein I wanted to provide html form frontends to an Excel spreadsheet sitting on a MS Windows server; with each authenticated HTTP user having thier own...
0
by: mb3242 | last post by:
Hello, I'm trying to use win32com to call a method in a COM object. I'm having a problem with Python choosing the wrong type when wrapping up lists into VARIANTs. The function I'm trying to call...
2
by: Sibylle Koczian | last post by:
Hello, I've installed Python 2.4 and the win32 extensions, using administrator rights, under Windows XP in "C:\Programme". As this is a directory without spaces I didn't expect any problems. But...
3
by: vml | last post by:
Hello, I am really new in python scipy win32com and scipy I tried to setup a COM server to interact with vb 6 the pythom COM server is : from win32com.server import exception, register import...
1
by: SPJ | last post by:
Sorry, forgot to mention Subject in my earlier post, hence reposting. ------------ I am writing a script which need's to convert an excel file to csv (text) format. For that I am using the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.