简体   繁体   中英

Get script name by PID

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM