Jump to content
Sign in to follow this  
burntfoot

Having issues trying to get run app on idle, close on wakeup script to work

Recommended Posts

I have a script that should execute upon user going idle. Once idle, I wanted a command window to open and pass the command to run a batch file. The batch file executes commands both in the command window and a powershell script in a powershell window. I have both of their paths set as environment variables in paths. The script runs fine on idle, but when moving my mouse upon wakeup, the command and powershell don't close. Could someone let me know what I'm doing wrong? My script below:

#include <Timers.au3>

While 1
   Sleep(10)
   $idleTimer = _Timer_GetIdleTime()
   If $idleTimer > 60000 And Not ProcessExists("cmd.exe") And Not ProcessExists("pwsh.exe") Then
      Run(@ComSpec & " /c " & "C:\Users\...\Desktop\mybatchfile.bat")
   ElseIf $idleTimer < 10 Then
      ProcessClose("cmd.exe")
      ProcessClose("pwsh.exe")
   EndIf
WEnd

 

Share this post


Link to post
Share on other sites

Here one way I would do it :

#include <Timers.au3>

Opt("MustDeclareVars", 1)

Local $idleTimer, $bIdle = False

HotKeySet("{ESC}", "_Exit")

While 1
  Sleep(10)
  $idleTimer = _Timer_GetIdleTime()
  If $idleTimer > 10000 Then
    ; maybe it should be a Or there instead of a And ?
    If Not ProcessExists("cmd.exe") And Not ProcessExists("pwsh.exe") Then Run(@ComSpec & " /c C:\Users\...\Desktop\mybatchfile.bat")
    $bIdle = True
  ElseIf $bIdle Then
    If ProcessExists("cmd.exe") Then ProcessClose("cmd.exe")
    If ProcessExists("pwsh.exe") Then ProcessClose("pwsh.exe")
    $bIdle = False
  EndIf
WEnd

Func _Exit()
  Exit
EndFunc   ;==>_Exit

This way you could create manually a cmd.exe console (for example) while not idle, but you would need to manually close it before going idle.  If this is not what you want, you will have to adjust the script accordingly... 

Share this post


Link to post
Share on other sites
#include <Timers.au3>

$Running = 0
While 1
    Sleep(10)
    $idleTimer = _Timer_GetIdleTime()
    If $idleTimer > 60000 Then
        If Not $Running Then $Running = Run(@ComSpec & " /c " & "C:\Users\...\Desktop\mybatchfile.bat")
    Else
        If $Running Then
            ProcessClose("pwsh.exe") ; tho, if you close this
            ProcessClose("cmd.exe") ; this should close itself
            $Running = 0
        EndIf
    EndIf
WEnd

PS: @Nine answered at the same time  :) 

Edited by argumentum
=)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...