SetFocus generates an error if the Window to get the focus dosn't exist.This script works if WordPad is opened, but crashes if WordPad is not opened.
code:
Break On
SetConsole("AlwaysOnTop")
$WinTittle = "Document - WordPad"
If SetFocus("$WinTittle") = 0
$Err = SendKeys("~{F4}")
EndIfReturn
I have tested this for Win95 and WinNT
Erik