Home > FAQ > Useful Basic Tasks when writing a script > How do I find the window which has the focus?

Window Instance

If you launch the same application several times, you must use an instance number to specify the desired copy of the application.

The window instance is an optional integer in a window name and specifies the instance of the launched application. 

The instance number can be omitted or set to 0. In that case, the first window found will be used. Instance numbers are assigned in the order in which the instances are launched, starting at 1.

This instance number can be found by the Spy tool.

UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad", 2)  'Instance 2 of notepad window