0

Here is my code to find the name of the active window. I now need to be able to find the location of the program.

 import win32gui
 window = win32gui.GetForegroundWindow()
 active_window_name = win32gui.GetWindowText(window)
 print(active_window_name)

How do i find the location of the program and file using either the name or anything else with out manually inputting the name.

2
  • Maybe not visible all ! Commented Apr 22, 2017 at 20:42
  • win32process.GetWindowThreadProcessId(window) will return the thread and process IDs that own the window. For a console window, the owner is conhost.exe, but the API special cases this to return either the initial process that attached to the console or, if that process has already exited, the current foreground process in the console. Commented Apr 22, 2017 at 21:52

1 Answer 1

2

I'm assuming you want to find the location of the file as in the directory path. There's multiple ways to do this, and the easiest one looks like this:

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.