ChrisD

Issues with Auto Starting and _Timer_GetIdleTime

4 posts in this topic

#1 ·  Posted

Hello everyone.  Thanks for taking the time to read my post.  I just learned about AutoIT a couple of weeks ago and have been pleasantly surprised at its functionality.  I administer a network with 60 end users and need to have a program run when:

  1. The computer first boots up regardless of login
  2. When the computer (keyboard and mouse) has been idle for a period of 20 minutes

I am using an AutoIT compiled exe to accomplish this task.  It works great when it is manually started by user interaction (clicking on it).  However when I run it with any of the following:

  1. Scheduled Task of the AutoIT compiled exe
    1. Ran at Startup
    2. Ran Manually
    3. Ran at a Scheduled Time
  2. As a service
  3. Executed remotely with PsExec

The programs referenced in the autoit code will execute immediately and not close when user interaction begins / resumes.

Any suggestions would be much appreciated.  The code is below (it will probably look familiar to many of you because parts of it come from the help file).

#include <Timers.au3>

$InactivityTrigger = 1200*1000 ;inactive for 20 Minutes

While True

    Dim $InactiveFor = _Timer_GetIdleTime()

    If $InactiveFor >= $InactivityTrigger And Not ProcessExists("RECavailable.exe") Then
         RunWait("genva.exe", "C:\windows\system32\")
         Sleep(1000)
         Run("RECavailable.exe -allvac/%computername% -colors 7", "", @SW_SHOWMAXIMIZED)
         ConsoleWrite("started" & @CRLF)

    ElseIf $InactiveFor < $InactivityTrigger Then

        ProcessClose("RECavailable.exe")
        ConsoleWrite("stopped" & @CRLF)

    EndIf

    If Not ProcessExists("RECavailable.exe") And Not IsFloat($InactiveFor/10) Then ToolTip("Inactive for: " & Round($InactiveFor/1000) & " seconds." & @CRLF & @CRLF & _
                   "Will run exe in " & Round( ($InactivityTrigger-$InactiveFor)/1000 ) & " seconds." )

Wend

As you can probably tell genva.exe is run one and done app before RECavailable.exe, its RECavailable.exe that is presenting the issues, as I mentioned earlier works great when I execute it manually just not in any of the other circumstances mentioned above.

On a side note I believe to be unrelated the primary issue I need to address as mentioned in this post is %computername% is not correctly passing the information as expected.  I can deal with that later or post a separate thread on that.

Thanks again to this awesome place. I am so glad I found AutoIT

Share this post


Link to post
Share on other sites



#2 ·  Posted

5 hours ago, ChrisD said:

2. When the computer (keyboard and mouse) has been idle for a period of 20 minutes

If the mouse has been idle for 20 minutes a msgbox will appear saying "PC is idle" for 5 seconds and idle until mouse moves again. 

#include <Timers.au3>
#include <MsgBoxConstants.au3>

while 1
    If _Timer_GetIdleTime() > 20000 Then

            ; Assume Idle
            MsgBox($MB_SYSTEMMODAL, "Idle", "PC is idle", 5)

            ; Now idle the script until it does something
            While _Timer_GetIdleTime() > 500
                Sleep(10)
            WEnd
    EndIf
WEnd

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Can you see what session ID the program and the AutoIt program are running on in Task Manager? _Timer_GetIdleTime only registers the last input from the session it's run from, which might cause some issues.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

18 hours ago, BrewManNH said:

Can you see what session ID the program and the AutoIt program are running on in Task Manager? _Timer_GetIdleTime only registers the last input from the session it's run from, which might cause some issues.

Thanks for the suggestion BrewMan.  Both are running under the same Session ID 0 when they are started with any of the mentioned methods that do not work: 

On 3/16/2017 at 11:15 AM, ChrisD said:
  • Scheduled Task of the AutoIT compiled exe
    1. Ran at Startup
    2. Ran Manually
    3. Ran at a Scheduled Time
  • As a service
  • Executed remotely with PsExec

However when manually starting the program (double clicking on it or executing via command line locally) both also get the same Session ID of 2, which has the program working as intended.  Thanks for pointing me this direction.  I also tried running psexec with a -i 2 command forcing session 2 and it worked. Is there anything I can do about that with my script.

 

aa2zz6

Sorry I really didn't go into detail in my first post regarding the operation of the last part of the script that also displays a tool tip with the idle time.

On 3/16/2017 at 11:15 AM, ChrisD said:
If Not ProcessExists("RECavailable.exe") And Not IsFloat($InactiveFor/10) Then ToolTip("Inactive for: " & Round($InactiveFor/1000) & " seconds." & @CRLF & @CRLF & _                    "Will run exe in " & Round( ($InactivityTrigger-$InactiveFor)/1000 ) & " seconds." )

 

Do you think that the code your provide may possibly help with the issue I am having?

Edited by ChrisD
Updating additional findings

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