Process information using Python, NOT using wmi, psutil, tasklist
Question: I'm writing a Python script that gets information on processes (PID, Command
Line, etc.) running on a PC.

On my Windows 7 PC I can use 'wmic' and use the output from that:

_output = subprocess.Popen(['wmic process get
creationdate,commandline,processid'], stdout=subprocess.PIPE,
shell=True).communicate()[0]_

Example of the info I can get from this output:

_PROCESS PID START TIME COMMAND: blah.exe 1234 Thu Jun 06 15:33:40 2013
C:\blah\blah.exe -a -b blah.txt_

This gives me all the info I need... HOWEVER not all machines will let me use
'wmic' as I'm not an Administrator.

I can use 'tasklist', but it doesn't give me the 'commandline' info that wmic
does.

I can't use 'psutils' (or the 'wmi' module), as it's not installed on any of
the PCs I need it to work on, and I don't want to have to get admin install
modules on all these PCs

Any ideas on how I can get the above process information using standard Python
2.6?

Thanks in advance, Nick

PYTHON 2.6 on Windows XP/7

=====================================================================

EDIT (12 June 2013):

I'm trying to do as suggested below, but having trouble... I've put the psutil
directory (psutil-0.7.1) in the same directory as my script and added the
following to my script:

path = '.\psutil-0.7.1'

sys.path.append(path)

import psutil

I now get the below error:

Traceback (most recent call last):

    
    
      File "C:\Users\nickw\Desktop\ProcessMonitor\ProcessMonitor_MODPS2.py", line 21, in <module>
    
        import psutil
    
      File ".\psutil-0.7.1\psutil\__init__.py", line 77, in <module>
    
        import psutil._psmswindows as _psplatform
    
      File ".\psutil-0.7.1\psutil\_psmswindows.py", line 15, in <module>
    
         import _psutil_mswindows
    
    ImportError: No module named _psutil_mswindows
    

Any idea what I'm doing wrong?


Answer: The technique to retrieve a process's command line is somewhat hacky but was
included into WMI since XP. Basically, it's reading another process's memory.
See e.g. [Getting another process command line in
Windows](http://stackoverflow.com/questions/6530565/getting-another-process-
command-line-in-windows) and links from there for details.

So, you either

  * re-implement it yourself by hand, with `ctypes` or whatever, like the link above says, or

  * somehow, utilize existing modules that will do that for you. There's [`zipimport`](http://docs.python.org/2/library/zipimport.html) to make this easier for multiple files and [`virtualenv`](https://pypi.python.org/pypi/virtualenv) to create whole environments anywhere on the filesystem, the latter likely being an overkill.

