Reputation: 2284
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.
Upvotes: 1
Views: 1956
Reputation: 7931
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()
Upvotes: 3