1

I've been trying to create a program that will identify was the active program on my computer is.

I am writing this code on python. On a windows computer. I don't need the PID i only need the name of the program running. When i say active i mean the program that is currently being used by a user.

I will eventually be able to take the active program and open it using

import os
os.startfile("C:\Program Files (x86)\Skype\Phone\Skype.exe") #skype for example
RaminNietzsche
  • 2,683
  • 1
  • 20
  • 34
  • Did you try searching for something like "Python list processes"? Then you simply find the one named "skype.exe" – OneCricketeer Apr 22 '17 at 18:43
  • The list processes give me all the running programs. I only need one name of the program and I don't want to manually put in the name to find it – Jonathan Kirshner Apr 22 '17 at 18:47
  • i just ran this code on a windows computer in spyder and i got the output "Active window: Spyder (Python 3.6)" -- http://stackoverflow.com/a/36419702/2601293 – J'e Apr 22 '17 at 18:48

1 Answers1

1

If you want to find active window, You can use win32gui on windows (find it in SourceForge):

import win32gui
window = win32gui.GetForegroundWindow()

with ctypes:

pid = ctypes.wintypes.DWORD()
active = ctypes.windll.user32.GetForegroundWindow()
active_window = ctypes.windll.user32.GetWindowThreadProcessId(active,ctypes.byref(pid)) 
RaminNietzsche
  • 2,683
  • 1
  • 20
  • 34