Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I want to be able to detect the presence of a specifically named window (in any process) to use as an "if" variable

After some research, I've concluded I must use the win32gui library (some posts also suggest ctypes ), but most of the posts I find are about making a list of processes , and the only one that was related to this topic didn't answer the question properly. Perhaps I am too novice to understand it, but at last, I couldn't get it to work (the question was this one )

To exemplify what I want, I'll share a simple .vbs code that does that: It searches for a specific name (in our case, steve jobs) and if it finds it anywhere, it triggers (in this example, it closes said process)

WindowTitle = "steve jobs" set shell = createObject("wscript.shell") success = shell.appactivate(WindowTitle) if success then shell.sendkeys "%{F4}" win32gui.FindWindowEx(0, 0, None, '<window_title_string>') is what I use, and check the Trueness of the returned hwnd to determine whether the window was found. jedwards Jun 12, 2018 at 20:28 Thank you for the reply! How do I test for that trueness? I tried using Test = win32gui.FindWindowEx(0, 0, None, 'name') and then I made a simple if Test == True: and it didn't work SaltyHelpVampire Jun 12, 2018 at 20:51 win2find = input('enter name of window to find') whnd = win32gui.FindWindowEx(None, None, None, win2find) if not (whnd == 0): print('FOUND!')

You can search Google for 'FindWindowEx'

to find https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v=vs.85).aspx

for a description of the FindWindowEx function

I tested it and it worked fine while testing with notepad and such, but for some reason it doesn't work with Google. The original idea I had was to detect google searches, but it doesn't work. I try putting the whole search (for example, if I want to detect "potato" I'll try detecting "potato - Google Search") and it doesn't work. How do I fix this? SaltyHelpVampire Jun 13, 2018 at 16:02 Good point - I took a look at the Task Manager and ... "potato - google-suche - mozilla firefox" works fine in good old germany ;) AcK Jun 13, 2018 at 21:34 Thank you so much! I just wrote "potato - Google Search - google chrome" and it worked perfectly! I'll instantly check your answer SaltyHelpVampire Jun 13, 2018 at 21:51 I know it has been a long time, but I wanted to ask you, how did you get the window title? As in, I go to Task Manager and I am not shown the window title, just the process ("chrome.exe" appears, and no "potato - Google Search - google chrome") SaltyHelpVampire Jul 20, 2018 at 13:21

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .