0

I am trying to get the list of opened applications in Windows but ended up getting the list of processes using

tasklist

I want to get the list of applications opened (not all processes) and their process id.

Ex: If a File Copy is going on then I want to know its process id and similarly if something is downloading in Chrome then I want to know the process id of that downloading window.

I am doing this in Python so solution can be anything related to Python or Command Prompt.

aki92
  • 2,064
  • 2
  • 14
  • 12

1 Answers1

3

If you want process please refer to this post @Nick Perkins and @hb2pencil gave a very good solution.

To get all opened application titles you can use the code below i am using it also in one of my drivers, it's from this site

There is also another post with similar question here and @nymk gave the solution.

import ctypes

EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int),     ctypes.POINTER(ctypes.c_int))
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
IsWindowVisible = ctypes.windll.user32.IsWindowVisible

def foreach_window(hwnd, lParam):

    titles = []

    if IsWindowVisible(hwnd):
        length = GetWindowTextLength(hwnd)
        buff = ctypes.create_unicode_buffer(length + 1)
        GetWindowText(hwnd, buff, length + 1)
        titles.append(buff.value)
        print buff.value

    return titles


def main():

    EnumWindows(EnumWindowsProc(foreach_window), 0)

   #end of main
if __name__ == "__main__":
    main()
Community
  • 1
  • 1
Kobi K
  • 7,743
  • 6
  • 42
  • 86
  • Thanks Kobi...but your code is giving me empty results even if many things are opened in my system. And the links you mentioned are nice but they don't solve my problem :( – aki92 Oct 12 '13 at 18:44
  • @aki92 It's strange this is the solution and it works for me, I am using it to catch windows of an oscilloscope driver and by another part i'm sending VISA commands to that window. Do you have open windows when you run it? – Kobi K Oct 12 '13 at 19:39
  • Yes I have many open windows when I run it, but still results are empty. – aki92 Oct 14 '13 at 07:09
  • I just tried it again, and it works. What is your OS? python Ver? – Kobi K Oct 14 '13 at 07:18
  • OS: Windows 8, Python Ver.: 2.7.4. – aki92 Oct 16 '13 at 15:04
  • Sory previously it was not working but now its working nicely and giving me the required results. But can I also get the corresponding Process ID so that I can check when they end? Please help me as now it seems I am very close to the thing what I want. – aki92 Oct 16 '13 at 15:13