1

I have 4 .bat-files in the Windows autostart folder for starting the programs Sabnzbd, CouchPotato, SickBeard and Headphones together with Windows. In these batch files I run the Python .py file through a line like this:

start "SABnzbd" pythonw "C:\SABnzbd\SABnzbd.py"

After all 4 programs have been started and are running I can see them in the WIndows task manager. However I cannot identify the separate processes. They all identify as pythonw.exe *32 with the description pythonw.exe:

enter image description here

What I'm trying to do is identifying every program. Do you have any idea how to do that? Could this be done by adding a parameter in the bat file? Or should I do something completely different?

Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
Dediqated
  • 901
  • 15
  • 35

5 Answers5

3

I'd suggest using python's WMI package (see this answer):

import wmi

c = wmi.WMI ()
for process in [p for p in c.Win32_Process () if p.Name == 'pythonw.exe']:
    print process.ProcessId, process.CommandLine
Community
  • 1
  • 1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • I'm sorry for the late reply, I was busy and forgot this question.. How would I get this to work? I saved it in a .py file but the command screen just flashes.. – Dediqated Aug 28 '13 at 16:22
  • ...and be sure not to launch it using pythonw. 8-) – mojo Sep 26 '13 at 13:08
0

You can use tasklist and filter the output to get all process ids (PIDs) related to a given name:

import os
def processes(name):
    os.system('tasklist /FI "IMAGENAME eq %s" > tmp.txt' % name)
    tmp = open('tmp.txt', 'r')
    return [int(i.split()[1]) for i in tmp.readlines()[3:]]

Then you can use the pids:

pids = processes('pythonw.exe') # <-- the name must be exact
Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
0

Use Pyinstaller to freeze python scripts file into exe file.

Then you can identify these processes by giving them different exe filename. e.g. Sabnzbd.exe, CouchPotato.exe, etc.

What's more, python interpreter is not needed installed on client's machine since you provide an exe file

Mark Ma
  • 1,342
  • 3
  • 19
  • 35
0

In batch, you can access WMI via wmic.exe (WMI Console)

wmic Path Win32_Process where Name='pythonw.exe' get ProcessId,CommandLine

The first quoted argument to the start builtin sets the window title. GUI features are not easily accessible by looking at processes. There are Win32 API's that do it (we use AutoIt for this purpose), but natively, I don't know how easy it is.

mojo
  • 4,050
  • 17
  • 24
0

I just solved it myself.

I've been stupid, I found out I can add colums to the processes tab in the Task manager. One of the columns available is Command line and that column shows exactly what I put in the .bat files including path and the path shows what program the process is.

Because of @Ansgar Wiechers' answer I've been looking to show the command line

Dediqated
  • 901
  • 15
  • 35