pythonwindowsfiletaskmanager

How to get apps list in task manager windows on python?


How to get this processes category on python? image I try to get all process, but I don't now how to get only this category of processes.


Solution

  • #!/usr/bin/python
    # -*- coding: utf8 -*-
    import subprocess
    import psutil
    
    pids = []
    
    cmd = 'powershell "gps | where {$_.MainWindowTitle } | select Id'
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    for line in proc.stdout:
        if line.rstrip():
            #print(line.decode().rstrip())
            pids.append(line.decode().rstrip())
    pids.remove('   Id')
    pids.remove('   --')
    
    for pid in pids:
        process = psutil.Process(int(pid))
        process_name = process.name()
        print(process_name)
    

    This is my answer