Jump to content

I would like to use win32 in python to create 2 functions


G+_theresa dela cruz
 Share

Recommended Posts

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

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

 Share

×
×
  • Create New...