Scripting WMI with win32com

Roger Upole rupole at msn.com
Fri Jan 26 17:07:18 EST 2001


Here's an example of how to call the Terminate method of a Win32_Process
instance,
where proc is the process object:

meth = proc.Methods_('Terminate')
parms=meth.InParameters
parms.Properties_('Reason').Value=69
proc.ExecMethod_('Terminate',parms)

             Roger Upole

"David Bolen" <db3l at fitlinxx.com> wrote in message
news:uitn2sw1z.fsf at ctwd0143.fitlinxx.com...
> I was wondering if anyone has done scripting of WMI with win32com and
> dealt with making method calls after parsing the typelib?  I've been
> experimenting to see if it would be usable for management of LANs in
> the field, and in general it looks nice, but I run into some issues
> when trying to invoke methods on provider objects (such as the Win32
> provider).
>
> What seems to happen is that running makepy on the provider library
> identifies all of the SWbem* objects, but when I obtain a provider
> object, it just looks like an instance of SWbemObject.  That makes
> sense, but I'm having difficulty figuring out how to invoke a method
> on such an object cleanly and access properties.  It would appear that
> both VBScript and JScript have some special support for this, which
> involves looking at the Properties_ and (I suppose) Methods_
> collections when a direct notation (e.g., object.value or
> object.call()) is used.
>
> I had some issues with accessing properties too, but found some older
> threads that showed a function-call method of doing a name lookup on
> the Properties_ value (or via the Item call) which works fine.  But
> I'm not quite sure how to play with the methods.
>
> In some respects, it's almost easier if I use the dynamic approach
> since I'm getting caught by the actual Python objects generated by
> makepy - if it just passes the attribute and method operations through
> they work.  (But of course I'm sure I'll find something that won't handle
> the parameters or output right without the typelib).
>
> Thanks for any help.
>
> --
> -- David
> --
> /-----------------------------------------------------------------------\
>  \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
>   |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
>  /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
> \-----------------------------------------------------------------------/





More information about the Python-list mailing list