Here is a more elaborate version
Code:
;======================================
; Change this parameters as desired
;======================================
external_program_name=Notepad
external_program_run=%SystemRoot%\system32\notepad.exe
check_delay=10000 ; wait before checking if program crashed
start_limit=5 ; limit the number of unsuccessful tries to open program
windows_boot_wait=30
;======================================
Settitlematchmode, 2 ; recognise partial titles
loop, %windows_boot_wait%
{
time_left:=windows_boot_wait-a_index
wait_msg=Waiting %time_left% seconds before starting%a_space%
msgbox,,,%wait_msg%%a_space%%external_program_name%,1
if time_left=1
break
}
start_count=0
loop
{
;k:=WinExist(%external_program_name%)
;msgbox %k%
;msgbox,,, %start_count%!%start_limit%,1
if (start_count > start_limit)
{
msgbox Failed to open %external_program_name% more than %start_limit% times. `nPlease contact treecar @ autohotkey`n Try again ?
start_count=0
}
IfWinNotExist , %external_program_name%
{
msgbox,,, not present %start_count%, 1
run, %external_program_run%
sleep, 2000 ; wait for program to run, otherwise you could have multiple copies
start_count++
}
else
{
msgbox,,, there it is, 1
start_count=0
sleep, %check_delay% ; wait before checking if program crashed
}
}
esc:: ; in case of emergency, press escape
exitapp