G+_theresa dela cruz Posted January 11, 2015 Share Posted January 11, 2015 I would like to use win32 in python to create 2 functions... 1. A function that checks if a certain application is running. 2. A function that checks if an application is installed... I have tried the following to check if something is running; def IsRunning(ProgramName): if win32ui.FindWindow(None, ProgramName): print("its running") return True else: print("its not running!") but the findwindow always trows an error if the program is not running before my program ever gets to the else statement and I do not know how to bypass that.... Any help would be very much appreciated as I can't find any info on this! Thanks Chris Link to comment Share on other sites More sharing options...
G+_Chris Stone Posted January 11, 2015 Share Posted January 11, 2015 Please reply to this account instead of the one above... I acidently used my friends account(sined into my computer at the time) to ask the question... thanks again... Link to comment Share on other sites More sharing options...
G+_Benjamin Breüner Frost Posted January 12, 2015 Share Posted January 12, 2015 i would try some thing like this try: if win32ui.FindWindow(None, ProgramName): print("its running") return True except: print("its not running!") i didn't try it myself but i thing it should work. Link to comment Share on other sites More sharing options...
G+_Chris Stone Posted January 13, 2015 Share Posted January 13, 2015 Thank you! this worked perfectly for my purposes... I needed to pass it like this; def IsRunning(WindowName): try: if win32ui.FindWindow(None, WindowName): print("its running") return True except win32ui.error: print("its not running!") return False The only difference being the win32ui.error part and you also need to put the window title exactly for it to pass the test... Then next thing I want to write is a similar function that uses regular expressions to find any part of a title name... Brilliant!!! Happy now :) Link to comment Share on other sites More sharing options...
G+_Benjamin Breüner Frost Posted January 13, 2015 Share Posted January 13, 2015 happy you could use it. Link to comment Share on other sites More sharing options...
Recommended Posts