-3

我需要验证一个进程是否仅使用 python 2.2 在 Windows(所有版本的 Windows XP 以上版本)中运行。任何想法?

4

3 回答 3

0

此代码适用于 Windows 上的 python 2.7。(我不确定它是否适用于 2.2 ......)

我使用 check_output() 函数来挂钩“tasklist”的输出,这是一个显示当前正在运行的进程的 Windows 命令。您可以解析 get_tasklist() 的结果以获取 pid、进程名称等。

import subprocess

def get_tasklist():
    return subprocess.check_output('tasklist')

print get_tasklist()

例子

除非您有特殊原因使用 2.2,否则将您的 python 升级到 2.7 怎么样?

于 2016-05-09T14:07:24.233 回答
0

看看这个帖子

http://code.activestate.com/recipes/305279/

问候

于 2016-05-09T14:07:55.920 回答
0

解决了:

from win32com.client import GetObject
WMI = GetObject('winmgmts:')

if len(WMI.ExecQuery('select * from Win32_Process where Name like "%s%s"' % ("process_name",'%'))) > 0:
    pass 
于 2016-05-09T16:15:28.753 回答