Search code examples
pythonprocesspid

Is there anyway to get process info by PID or name on Windows using Python?


I need to get process info by using PID or Name on Win 10, using only standard library.

Is this possible?

EDIT:

I meant all processes, not current...


Solution

  • You can use subprocess

    from subprocess import getoutput
    
    process_info = getoutput('wmic process where "name like \'%{}%\'" get Caption,ExecutablePath,Processid,CommandLine'.format('chrome.exe'))
    
    process_info = getoutput('wmic process where "ProcessID={}" get Caption,ExecutablePath,Processid,CommandLine'.format(14520))