コード例 #1
0
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
コード例 #2
0
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
コード例 #3
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)
コード例 #4
0
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
コード例 #5
0
def getParentProcessId(pid):
    rst, count = autoutil.queryWmi('select * from Win32_Process where ProcessId = %d' % pid)
    if count:
        return rst[0].ParentProcessId
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
def getProcessIds():
    rst, count = autoutil.queryWmi('select * from Win32_Process')
    pidList = []
    for i in range(count):
        pidList.append(rst[i].ProcessId)
    return pidList
コード例 #9
0
def getProcessIdsByName(pname):
    rst, count = autoutil.queryWmi('select * from Win32_Process where Name = "%s"' % pname)
    return [item.ProcessId for item in rst]
コード例 #10
0
def getProcessIdByName(pname):
    rst, count = autoutil.queryWmi('select * from Win32_Process where Name = "%s"' % pname)
    if count:
        return rst[0].ProcessId