Win32_Process.Create -- not starting process

Tim Golden tim.golden at viacom-outdoor.co.uk
Tue Feb 14 12:07:36 EST 2006


[abcd]

| I am using Python to create a process on another computer.  Both
| computers are on the same domain with admin privileges.
| 
| On computer B I have a batch script which starts a python 
| script.  From computer A I am doing the following:
| 
| import wmi
| w = wmi.WMI("1.2.3.4")
| p = w.new("Win32_Process")
| pid, retVal = p.Create(CommandLine="C:\\a_script.bat")
| print pid, retVal
| 
| The output I get is, 1218 0  ....0 = "Successful Completion"

| ....however the python script that is called from the batch script
| never seems to run or at least only for a split second.  Sometimes I
| see python.exe appear in the task manager on computer B for a split
| second then it goes away.  So I went to computer B and double clicked
| on the batch script, and sure enough a command opened up and 
| the python script was running...and stayed running...no problem.   
| I should mention, that sometimes it will execute the batch script and 
| the Python script will run and stay running.  That has only happened 
| after trying to do "p.Create(CommandLine....)" more than once, but not

| every time I try.
| 
| Any ideas why its not working for me remotely....or why its random?
| These are win xp machines with no firewalls running.

OK, let me say up front: there's nothing terribly obvious. Just in 
case you haven't, it's probably worth your running the latest 
wmi module -- 1.0rc6 at time of writing -- which makes slightly
cleaner the interface to WMI classes. However, that's not the
problem here, as the syntax you're using above works in 0.6b
and in 1.0rc6 (I just tried both).

I *think* that what you're seeing is that the script isn't running
in the environment you're expecting, and is then swallowing the
problem. Can you confirm whether or not the simplest possible
Python script does indeed run and produce the expected result?
You may well have to specify an explicit path for Python,
give explicit paths for output files and so on.

My test case, for example, which ran consistently, was: 

## on the remote machine

<c:\temp\wmi-test\test.cmd>
c:\python23\python c:\temp\wmi-test\test.py
</c:\temp\wmi-test\test.cmd>

<c:\temp\wmi-test\test.py>
import os
f = open ("c:\\temp\\wmi-test\\test.txt", "w")
f.write ("%s\n" % os.getcwd ())
for k, v in os.environ.items ():
  f.write ("%s => %s\n" % (k, v))
f.close ()
</c:\temp\wmi-test\test.py>

## on my machine

<code>
import wmi
c = wmi.WMI ("vogbp364") # obviously your remote machine name
#
# Slightly cleaner syntax new to wmi 1.0
#
c.Win32_Process.Create (CommandLine=r"c:\temp\wmi-test\test.cmd")
</code>

Obviously the extent to which you'll need to
specify things will be affected by the system-level
as opposed to user-level info on each machine.

Hope that helps. Feel free to get back if it doesn't.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. 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