[python-win32] Executing a remote process via WMI in Win32.

Sean null-python-win32 at tinfoilhat.ca
Mon Jul 7 18:17:14 EDT 2003


I apologize for the cross post on comp.lang.python but I've yet to get any
reply.

I can connect to a machine remotely with no problems but I'm having
trouble trying to create a process remotely.  Initially this was a perl
and VB script which I'm converting to python.  Its entire purpose is to
start a process remotely.  The problem initially was that the perl script
could not 'see' any mapped drives as it would alway return 'access denied'
so I'm trying to not only rewrite the script but fix this problem and my
idea was to connect with the Administrator account.

Now the following script sort of works.  I can get the set of running
processes but it dies out when I try to create one.

## being ##
import win32com.client
wmi = win32com.client.Dispatch('wbemscripting.swbemlocator')
remote_machine =
wmi.ConnectServer('<MACHINE>','root\\cimv2',Administrator','<PASSWORD>')

process = remote_machine.InstancesOf("Win32_Process")
for proc in process:
    size = int(proc.WorkingSetSize)/1024
    print proc.Caption, size,"kb"
# test to see if we can 'see' what's on a mapped drive.
# doesn't seem to go.
process.Create("cmd.exe /K dir w:\\")
## END ##

The script will print out all the processes fine but once it get's to
'Create' it dies out with and error message I don't understand.

NOTEPAD.EXE 80 kb
Traceback (most recent call last):
  File "C:\Documents and Settings\scody\test.py", line 14, in ?
    process.Create("cmd.exe /K dir w:\\")
  File "C:\Python23\lib\site-packages\win32com\client\dynamic.py", line
460,
in
__getattr__
    raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: InstancesOf.Create

The process method should only have the one parameter as defined at:
http://userpages.umbc.edu/~kbradl1/wsz/ref/WMIref.html#process

I just tried using the 'Terminate' process but that didn't work either....

So I'm going to assume that the WMI objects are not instantiated as python
classes (hence why the methods are not working).  Am I completely off base
here (meaning it is a syntax problem)?

The whole point of this is that I'd like to automate software updates on a
large set of machines and in order for this to work I need to copy files
from a common share and run a specific application on each machine to
finalize the installation.

Any suggestions or pointers to the right direction would be creately
appriciated...

--
Sean





More information about the Python-win32 mailing list