Page 1 of 1

Looking for a script to close a specific program and then put PC to sleep

Posted: 27 Apr 2024, 10:50
by loadinator
I have a program that i need closing after a certain amount of time, lets say one hour, then i want the PC to sleep straight after, does anyone know of a script that can do this?

Re: Looking for a script to close a specific program and then put PC to sleep

Posted: 27 Apr 2024, 12:24
by mikeyww

Code: Select all

#Requires AutoHotkey v2.0
winTitle       := 'ahk_exe Notepad.exe'
closeAfterMins := 60
SoundBeep 2500
WinWait winTitle
SoundBeep 1500
If !WinWaitClose(,, 60 * closeAfterMins) {
 WinClose
 SoundBeep 1000
 DllCall('PowrProf\SetSuspendState', 'Int', 0, 'Int', 0, 'Int', 0) ; Sleep computer
}
ExitApp