win32com (VBScript to Python) problem

Tim Howarth tim at worthy.demon.co.uk
Tue Nov 25 12:16:25 CET 2003



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=impersonate,(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:{impersonationLevel=impersonate,\
 (Shutdown)}!\\" + pc + r"\root\cimv2")
 
 colOperatingSystems = oWMI.ExecQuery(r"Select * from Win32_OperatingSystem")
 
 for obj in colOperatingSystems:
     obj.Win32ShutDown(12)




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




More information about the Python-list mailing list