The easiest was would be finding the window by its class name or using a wildcard on its title:--local swnd = acFindWindow("Notepad",nil) --this line would match on exact class name
local swnd = acFindWindowByTitleRegex(".* - Notepad") --finds by title wildcard
if swnd > 0 then
acCloseApplication(swnd)
else
acRunProgram("c:\\windows\\notepad.exe","",0, 1)
end