win32com (VBScript to Python) problem

Tim Golden tim.golden at viacom-outdoor.co.uk
Tue Nov 25 10:18:33 EST 2003


> > http://tgolden.sc.sabren.com/python/wmi_cookbook.html
> > (search for "Reboot a remote machine" -- I really must put 
> anchors on that
> > page)
> > 
> > If you follow that example, all you need to change is the final line
> >  to read something like:
> > 
> > os.Win32Shutdown (Flags=12)
> 
> Thanks to Tim, that works, though I still wonder why I can't do it
> my original way.

For the purposes of elucidation, I offer the following 
 half-baked explanation, based on my re-reading my own
 code:

For reasons unknown to me, you don't simply call an arbitrary 
 named method on a WMI object; rather, you call the ExecMethod_ 
 method of the object, having passed parameters in, which must
 themselves have been set up via Methods_ ().InParameters. The
 result and any outward parameters are picked up via the
 OutParameters property. (That was a bit simplified).

Obviously, given the win32com module you can do all this by
 yourself. When all's said and done, that's exactly what my
 module is doing. However, it's as tedious as anything. So...
 the wmi module sets up a combination of __getattr__ hooks and
 currying classes to take the burden away from you.

If you're interested enough, the relevant -- underdocumented -- code 
 is in the _wmi_method class of the wmi module, hooked into from
 the __getattr__ method of the _wmi_object class which tries
 to work out whether you're referring to a method (in which case it
 sets up a proxy instance which is then called) or a property (in
 which case it returns the .Value property of the named property).

There is a __setattr__ counterpart to all this, but as has been
 pointed out several times recently on this list, WMI is given 
 more to reading than to writing.

Well... you did ask! I would add, finally, that putting this code
 together some six months ago now, was both an education and a
 valuable experience, not simply in learning about WMI, but also
 in just how much information is available in the c.l.py archives
 if you look hard enough. I raise my hat to all those who have
 posted working code and explanations over the years.

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________





More information about the Python-list mailing list