[python-win32] Executing a remote process via WMI in Win32.
Tim Golden
tim.golden at viacom-outdoor.co.uk
Tue Jul 8 17:07:19 EDT 2003
After a bit of to-ing and fro-ing (and help from
Paul Moore) I've had some success with the following:
<code>
import wmi
c = wmi.WMI ("remote_machine")
for p in c.Win32_Process (name="notepad.exe"): print p
c.new ("Win32_Process").Create (CommandLine="notepad.exe")
for p in c.Win32_Process (name="notepad.exe"): print p
p.Terminate ()
for p in c.Win32_Process (name="notepad.exe"): print p
</code>
(Don't do this to a colleague's machine where notepad is
already running!)
Notes:
This example uses the updated version of the wmi
module (at http://tgolden.sc.sabren.com/python/wmi.html)
but if you're not bothered, all it's doing is attaching
to the remote server and then doing a .Get on the class
name and calling .Create on the resulting class object.
The process you create won't be visible on the other machine,
but you can see it via Task Manager (and via WMI as shown
above, obviously). Microsoft caveats state that any remote
process created this way will be non-interactive.
Both Paul & I had Admin privs on the machines we were
creating processes on, and I haven't checked what happens
when you try without. However, I expect that you'll have
some kind of Admin right before you try to do this
kind of thing anyway.
Hope this helps.
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-win32
mailing list