Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 03, 2015, 06:27:02 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: utility to close a program after the program has been idle for x minutes  (Read 8460 times)

go197

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 12
    • View Profile
    • Donate to Member
I keep my email .pst file and my MS OneNote data inside an encrypted "drive" that closes itself after 15 minutes of no read/write activity to the "drive".  I have always wanted a utility that I could set up to close out Outlook and/or OneNote 1 minute before the encrypted "drive" closes.  This way I could avoid the programs becoming non-responsive and/or the PC blue screening when I try to reopen the drive.
This kind of utility could be useful for anyone who might want a program to close by itself for other reasons, like password protected files (Word, Excel, etc) or other password protected apps. 
It might also be useful if it could close programs due to screen saver activation, hibernation, or stand-by.
I hope this sounds interesting to you guys, I think it could be useful.
Thanks in advance...
« Last Edit: December 22, 2006, 04:40:02 AM by brotherS »

go197

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 12
    • View Profile
    • Donate to Member
OP here.  I was looking through the finished programs in this forum after I posted the above request (should've been more thorough to begin with  :-[ ...sorry :'() and found this:
http://www.donationc...dex.php?topic=2377.0
This might be what I've been looking for.  I'll look at it and see if it will work for my situation.

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,122
    • View Profile
    • Donate to Member
http://www.donationc...dex.php?topic=2377.0
This might be what I've been looking for.  I'll look at it and see if it will work for my situation.
Yep, my script at the end of that thread should do exactly what you want. If you can't get it to work for your program(s), please reply there.

go197

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 12
    • View Profile
    • Donate to Member
Thanks for your reply.  Yes it works with outlook.exe and onenote.exe,  but I've found after testing it and reading about the A_TimeIdlePhysical command in the help file that it's not exactly what I'm looking for.  I am looking for a utility that monitors the idle time of only specific programs (instead of the whole system) and that would then close those programs after x minutes of program idle time.  I can see that this script you wrote is useful for many purposes, but it's not really what I am needing.  I'm looking for a solution to close Outlook and OneNote before Truecrypt's "auto-close on x minutes with no read/writes" feature closes the "drive" where their data is located because this "drive" closing causes problems as I mentioned above.  I don't know if you're familiar with the Truecrypt feature I'm refering to, so if you need me to elaborate a little, I can.  Is there anything that can be done with Autohotkey that could help with my situation?

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,122
    • View Profile
    • Donate to Member
Is there anything that can be done with Autohotkey that could help with my situation?
It's AutoHotkey: of course! :)

I imagine something like "check if PROGRAM's window is active" (If WinActive, check out http://www.autohotke...om/docs/commands.htm) - if it hasn't been active for x minutes -> close PROGRAM.

Some of the more experienced AutoHotkey users here can probably help you with more details.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Read more about this member.
    • Donate to Member
Just let me straighten out some stuff: The time that it'd wait before closing the programs would be the same for all of them, right?
Also, would you like it to close the program's windows or to terminate the processes?

go197

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 12
    • View Profile
    • Donate to Member
I imagine something like "check if PROGRAM's window is active" (If WinActive, check out http://www.autohotke...om/docs/commands.htm) - if it hasn't been active for x minutes -> close PROGRAM.
Would this work if the Outlook window was the only window open?  If not, then I guess I'm needing something that monitors the activity (or lack of it) happening with the program or maybe there is a creative way to get the same effect.

Just let me straighten out some stuff: The time that it'd wait before closing the programs would be the same for all of them, right?
Yes, that would work for me since any i/o to the "drive" resets the "drive's" idle timer.  For example, if Outlook and OneNote were both open but I was only doing anything in Outlook, that would be enough to keep the "drive" open and therefore OneNote is safe from the "drive" closing too.

Also, would you like it to close the program's windows or to terminate the processes?
A nice gentle "close" would be best I guess, if that's an option.
« Last Edit: December 22, 2006, 10:21:38 PM by go197 »

go197

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 12
    • View Profile
    • Donate to Member
Well this has been dropping down the list, so does that mean that it isn't possible with AHK?

brett

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 125
  • Australia
    • View Profile
    • Donate to Member
Just a thought

Your problem is having a program still running that can no longer access the drive, because the drive has disconnected due to lack of activity.

It would not be to hard to have a AHK script send a tiny write/delete to the encrypted drive every 'x' minutes whenever Outlook/Onenote is open (IfWinExists)
Keeping the encrypted drive active until you close Outlook/Onenote

is this a option ?

..dB..
doublebogey
« Last Edit: December 27, 2006, 01:51:52 PM by doublebogey »

go197

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 12
    • View Profile
    • Donate to Member

Just a thought

Your problem is having a program still running that can no longer access the drive, because the drive has disconnected due to lack of activity.

It would not be to hard to have a AHK script send a tiny write/delete to the encrypted drive every 'x' minutes whenever Outlook/Onenote is open (IfWinExists)
Keeping the encrypted drive active until you close Outlook/Onenote

is this a option ?

..dB..
doublebogey


Well, that is a good idea  :D, but I want the drive to close to protect my data, so I'd rather the drive close itself for security.
But thank you...


skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
 :) 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.autohotke...?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
}

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

go197

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 12
    • View Profile
    • Donate to Member
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: ...



« Last Edit: December 27, 2006, 08:38:00 PM by go197 »