无论如何,是否可以使用 Python 在 Windows 上通过 PID 或名称获取进程信息?
Is there anyway to get process info by PID or name on Windows using Python?
我需要在 Win 10 上使用 PID
或 Name
获取进程信息,仅使用 标准库 。
这可能吗?
编辑:
我的意思是所有进程,不是当前进程...
您可以使用子流程
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))
我需要在 Win 10 上使用 PID
或 Name
获取进程信息,仅使用 标准库 。
这可能吗?
编辑:
我的意思是所有进程,不是当前进程...
您可以使用子流程
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))