通过psutil模块读取机器进程信息:
#-*- coding: UTF-8 -*-
import psutil;
import os
import CommMethod
‘‘‘获取机器当前进程信息‘‘‘
def GetCurrentProcessInfo():
lst1= psutil.pids()
lst1.sort()
for i in lst1:
temp =""
flag=True
# 文件名称
filename = psutil.Process(i).name()
#文件全路径
filePath =""
#文件版本号
version = ""
#安装时间
installTime = ""
#访问时间
accessTime = ""
#启动时间
startTime = ""
try:
#文件路径
filepath = psutil.Process(i).exe()
#启动时间
startTime = CommMethod.TimeStampToTime(psutil.Process(i).create_time())
#版本信息
version = CommMethod.GetFileVersion(filepath)
installTime = os.path.getctime(filepath)
accessTime = os.path.getatime(filepath)
#把时间戳转为时间格式
installTime = CommMethod.TimeStampToTime(installTime)
accessTime = CommMethod.TimeStampToTime(accessTime)
except:
flag=False
finally:
if(len(version)>0 and len(installTime)>0):
print ‘id=%d,name=%s,fileName =%s,version=%s, installTime=%s,accessTime=%s,startTime = %s‘ % (i,psutil.Process(i).name(),filename,version,installTime,accessTime,startTime)
GetCurrentProcessInfo()