views:

42

answers:

1

How would I use Python to determine what programs are currently running. I am on Windows.

+3  A: 
import os
os.system('WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid')
f = open("C:\ProcessList.txt")
plist = f.readlines()
f.close()

Now plist contains a formatted whitespace-separated list of processes:

  • The first column is the name of the executable that is running
  • The second column is the command that represents the running process
  • The third column is the process ID

This should be simple to parse with python. Note that the first row of data are labels for the columns, and not actual processes.

Note that this method only works on windows!

hb2pencil