0

I have a list of PID and need the Python script names. Is there a way to resolve the PID?

I tried it already with psutil and subprocess, but I just get 'python.exe' returned.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Does this answer your question? [How to get the command line args passed to a running process on unix/linux systems?](https://stackoverflow.com/questions/821837/how-to-get-the-command-line-args-passed-to-a-running-process-on-unix-linux-syste) – mkrieger1 May 31 '21 at 19:12
  • Oh sorry, I missed that you seem to be on Windows. – mkrieger1 May 31 '21 at 19:13

1 Answers1

1

You could solve this with WMIC:

wmic process get processid,commandline

or with a WMI query:

Get-WmiObject -Query "SELECT CommandLine FROM Win32_Process WHERE ProcessID = 1"

There is also a python WMI wrapper if you want to do this in python code: https://pypi.org/project/WMI/

Edit: After some research, I have found out that it is possible to achieve this with psutils too. Just invoke cmdline on your process instance. -> https://psutil.readthedocs.io/en/latest/#psutil.Process.cmdline

zanseb
  • 1,275
  • 10
  • 20