DonationCoder.com Software > Post New Requests Here
IDEA: utility to close a program after the program has been idle for x minutes
skrommel:
:) I didn't read the whole request, and figured you wanted to use the prosess' CPU usage, but here's an attempt.
IdleClose - Closes programs that's not been activated for x minutes
It's a bit rough around the edges, as it tries to close the same program several times if it has several windows, and a few other things, but I'll correct it when I write a GUI for it tomorrow.
It is set to close any windows not accessed within 1 minute, but it asks first, and if you say No, the window is ignored in the future. You can change the list of ignored programs, and also kill programs instead of just trying to close them.
Skrommel
;IdleClose.ahk
; Closes programs that's not been activated for x minutes
;Skrommel @2006
...
Spoiler;IdleClose.ahk
; Closes programs that's not been activated for x minutes
;Skrommel @2006
idletime=0001 ;HHMM
letlive=Explorer.exe,Progman.exe ;<programname>,<programname>
kill=0 ;0=close 1=kill
confirm=1 ;0=ask before closing 1=don't ask
#SingleInstance,Force
#NoEnv
SetWinDelay,0
applicationname=IdleClose
ids=
idletime=%idletime%00
WinGet,list,List
Loop,% list
{
id:=list%A_Index%
ids=%ids%%id%,
%id%:=A_Now
}
SetTimer,KILL,10000
SetTimer,CLEAN,60000
activeid:=WinExist("A")
Loop
{
WinWaitNotActive,ahk_id %activeid%
activeid:=WinExist("A")
%activeid%:=A_Now
IfNotInString,ids,%activeid%`,
ids=%ids%%activeid%,
}
KILL:
%activeid%:=A_Now
WinGet,list,List
Loop,% list
{
id:=list%A_Index%
time:=%id%
If (time+idletime<A_Now)
{
WinGet,pid,PID,ahk_id %id%
path:=GetModuleFileNameEx(pid)
SplitPath,path,name
If name In %letlive%
Continue
If confirm=1
{
MsgBox,4,%applicationname%,Really close %name%?
IfMsgBox,No
{
letlive=%letlive%,%name%
Continue
}
}
If kill=1
Process,Close,%pid%
Else
WinClose,ahk_id %id%
}
}
Return
CLEAN:
newids=
Loop,Parse,ids,`,
{
If A_LoopField=
Continue
IfWinExist,ahk_id %A_LoopField%
newids=%newids%%A_LoopField%,
Else
%A_LoopField%=
}
ids=%newids%
Return
GetModuleFileNameEx( p_pid ) ;by shimanov at http://www.autohotkey.com/forum/viewtopic.php?t=4182&start=15
{
if A_OSVersion in WIN_95,WIN_98,WIN_ME
{
MsgBox, This Windows version (%A_OSVersion%) is not supported.
return
}
/*
#define PROCESS_VM_READ (0x0010)
#define PROCESS_QUERY_INFORMATION (0x0400)
*/
h_process := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", p_pid )
if ( ErrorLevel or h_process = 0 )
{
MsgBox, [OpenProcess] failed
return
}
name_size = 255
VarSetCapacity( name, name_size )
result := DllCall( "psapi.dll\GetModuleFileNameExA", "uint", h_process, "uint", 0, "str", name, "uint", name_size )
if ( ErrorLevel or result = 0 )
MsgBox, [GetModuleFileNameExA] failed
DllCall( "CloseHandle", h_process )
return, name
}
go197:
Looking good Skrommel :beerchug:!!
Before you get too far can I throw out a few thoughts for design? (I don't need all of these features, but maybe someone else might be able to use them)
Maybe have a list of specified apps for it to monitor while all others are ignored
Maybe be able to choose whether to display the "Really close?" dialog for each app
Maybe have a "Snooze" option on the "Really close?" dialog
Maybe have options to also close the programs on hibernate, stand-by, and screen-saver
Also, with the aim of flexibility, maybe give the option of (instead of killing a process or closing a program) setting it to run a program or batch file
My :two: ...
Navigation
[0] Message Index
[*] Previous page
Go to full version