def getUserProcessIds(user): rst, count = autoutil.queryWmi('select * from Win32_Process') pidList = [] for i in range(count): owner = autoutil.tryExcept(rst[i].ExecMethod_, 'GetOwner') if not autoutil.isExcept(owner) and owner.User and owner.User.lower() == user.lower(): pidList.append(rst[i].ProcessId) return pidList
def existProcessByIds(pidList, isAll = False): sql = 'select * from Win32_Process where (' for pid in pidList: if not sql.endswith('('): sql += ' or ' sql += 'ProcessId = %d' % (pid,) sql += ')' count = autoutil.queryWmi(sql)[1] if isAll: return count == len(pidList) return count > 0
def getChildProcessIds(pid, rpidList = []): if pid in rpidList: return [] rpidList = copy.copy(rpidList) rpidList.append(pid) rst, count = autoutil.queryWmi('select * from Win32_Process where ParentProcessId = %d' % pid) cpidSet = set() for i in range(count): if rst[i].ProcessId in rpidList: continue cpidSet.add(rst[i].ProcessId) cpidSet.update(getChildProcessIds(rst[i].ProcessId, rpidList)) return list(cpidSet)
def existProcessByNames(pnameList, isAll = False): try: sql = 'select * from Win32_Process where (' for pname in pnameList: if not sql.endswith('('): sql += ' or ' sql += 'Name = "%s"' % (pname,) sql += ')' rst, count = autoutil.queryWmi(sql) if isAll: pnameSet = set() for i in range(count): pnameSet.add(rst[i].Name.encode(sys.getfilesystemencoding())) return len(pnameSet) == len(pnameList) return count > 0 except: print 'psutil query proc' pnames = getProcessNamesByPsutil() for pname in pnameList: if not pname.lower() in pnames: return False return True
def getParentProcessId(pid): rst, count = autoutil.queryWmi('select * from Win32_Process where ProcessId = %d' % pid) if count: return rst[0].ParentProcessId
def getCmdLineById(pid): rst,count= autoutil.queryWmi('select * from Win32_Process where ProcessId=%s' % pid) if count: cmdLine = autoutil.tryExcept(rst[0].CommandLine.encode, sys.getfilesystemencoding()) if not autoutil.isExcept(cmdLine): return cmdLine
def getProcessNameById(pid): rst, count = autoutil.queryWmi('select * from Win32_Process where ProcessId = %d' % pid) if count: pname = autoutil.tryExcept(rst[0].Name.encode, sys.getfilesystemencoding()) if not autoutil.isExcept(pname): return pname
def getProcessIds(): rst, count = autoutil.queryWmi('select * from Win32_Process') pidList = [] for i in range(count): pidList.append(rst[i].ProcessId) return pidList
def getProcessIdsByName(pname): rst, count = autoutil.queryWmi('select * from Win32_Process where Name = "%s"' % pname) return [item.ProcessId for item in rst]
def getProcessIdByName(pname): rst, count = autoutil.queryWmi('select * from Win32_Process where Name = "%s"' % pname) if count: return rst[0].ProcessId