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
3
  • Did you try searching for something like "Python list processes"? Then you simply find the one named "skype.exe" Commented Apr 22, 2017 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 Commented Apr 22, 2017 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)" -- stackoverflow.com/a/36419702/2601293 Commented Apr 22, 2017 at 18:48

1 Answer 1

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)) 
Sign up to request clarification or add additional context in comments.

7 Comments

try this: ctypes.windll.user32.GetForegroundWindow()
When i used that code by itself, it returned a number, what is that number and how would i instead get a file name
I was able to use win32gui but still, what about the number i get, what is that and how do i get the name
@JonathanKirshner read this: stackoverflow.com/questions/37501191/…
Sorry but I still don't understand, how do i get a program name?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.