Jump to content

_Timer_GetIdleTime() failing after 30 - 50 minutes?


Recommended Posts

I am running a program on a Terminal Server that detects when you've idled for too long. For some reason the program seems to stop after being disconnected from the Terminal Server for 30-50 minutes. I don't understand why it's stopping.

I've added some FileOutput to try to isolate the issue. I can not, for the life of me figure it out.

Any help is much appreciated.

Thank you!

#include <Misc.au3>
_Singleton("AmericanIdle")
#NoTrayIcon
#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
#include <StaticConstants.au3>

Opt('WINTITLEMATCHMODE', 4)
#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

While 1
    Sleep(2000)
    $log = FileOpen("H:\American"& @ComputerName &"IdleLog.txt", 1)
; Check if file opened for writing OK
    If $log = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    Global $iIdleTime = _Timer_GetIdleTime()
        ConsoleWrite("idletime = " & Round($iIdleTime/1000,0) & @CRLF)
        FileWrite($log, "idletime = " & Round($iIdleTime/1000,0))
        if $iIdleTime >$idletimeout Then
            ConsoleWrite("Hit the Limit of " & ($idletimeout/1000) & " Seconds at "&@HOUR&":"&@MIN&":"&@SEC & @CRLF)
            FileWriteLine($Log,"Hit the Limit of " & ($idletimeout/1000) & " Seconds at "&@HOUR&":"&@MIN&":"&@SEC)
        Local $foo = Run(@ComSpec & " /c qwinsta " & $un & " /server:" & $cn, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
        Local $line
        While 1
            $line = StdoutRead($foo)
            If @error Then ExitLoop
            $linelen = StringLen($line)
            if $linelen >0 Then
                ConsoleWrite("Primary Loop DOS return" & $line & @CRLF)
                FileWriteLine($log,"DOS return" & $line)
                $test = StringInStr($line,"Active",0)
                ConsoleWrite("Line test (0 > GUI)" & $test & @CRLF)
                FileWriteLine($log,"Line test (0 > GUI)" & $test)
                    if $test > 0 then
                    FileWriteLine($log,"Opening GUI")
                    ConsoleWrite("Opening GUI" & @CRLF)
                                gui()
                EndIf
            EndIf
        WEnd
        While 1
            $line = StderrRead($foo)
            If @error Then ExitLoop
            MsgBox(0, "STDERR read:", $line)
            ConsoleWrite("STDERR read:" & $line)
            FileWriteLine($log,"STDERR read:" & $line & @CRLF)
        Wend
        StdioClose($foo)
        EndIf
    FileClose($log);close log
WEnd
Link to comment
Share on other sites

Where and how is $idletimeout declared?

:)

I messed up. I notated what I missed before.

#include <Misc.au3>
_Singleton("AmericanIdle")
#NoTrayIcon
#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
#include <StaticConstants.au3>

Opt('WINTITLEMATCHMODE', 4)
#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

$idletimeout = "25000";Missed this before!

While 1
    Sleep(2000)
    Global $iIdleTime = _Timer_GetIdleTime() ;Missed this before!
    $log = FileOpen("H:\American"& @ComputerName &"IdleLog.txt", 1)
; Check if file opened for writing OK
    If $log = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    Global $iIdleTime = _Timer_GetIdleTime()
        ConsoleWrite("idletime = " & Round($iIdleTime/1000,0) & @CRLF)
        FileWrite($log, "idletime = " & Round($iIdleTime/1000,0))
        if $iIdleTime >$idletimeout Then
            ConsoleWrite("Hit the Limit of " & ($idletimeout/1000) & " Seconds at "&@HOUR&":"&@MIN&":"&@SEC & @CRLF)
            FileWriteLine($Log,"Hit the Limit of " & ($idletimeout/1000) & " Seconds at "&@HOUR&":"&@MIN&":"&@SEC)
        Local $foo = Run(@ComSpec & " /c qwinsta " & $un & " /server:" & $cn, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
        Local $line
        While 1
            $line = StdoutRead($foo)
            If @error Then ExitLoop
            $linelen = StringLen($line)
            if $linelen >0 Then
                ConsoleWrite("Primary Loop DOS return" & $line & @CRLF)
                FileWriteLine($log,"DOS return" & $line)
                $test = StringInStr($line,"Active",0)
                ConsoleWrite("Line test (0 > GUI)" & $test & @CRLF)
                FileWriteLine($log,"Line test (0 > GUI)" & $test)
                    if $test > 0 then
                    FileWriteLine($log,"Opening GUI")
                    ConsoleWrite("Opening GUI" & @CRLF)
                                gui()
                EndIf
            EndIf
        WEnd
        While 1
            $line = StderrRead($foo)
            If @error Then ExitLoop
            MsgBox(0, "STDERR read:", $line)
            ConsoleWrite("STDERR read:" & $line)
            FileWriteLine($log,"STDERR read:" & $line & @CRLF)
        Wend
        StdioClose($foo)
        EndIf
    FileClose($log);close log
WEnd
Edited by inm101
Link to comment
Share on other sites

  • Moderators

No idea what you're really doing here, but "25000" is a string. So you're comparing a Number/Integer to a String intentionally?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

No idea what you're really doing here, but "25000" is a string. So you're comparing a Number/Integer to a String intentionally?

No, not doing it intentionally.

To answer your question: I am watching an idle time. Once I hit the idle time I run the "Qwinsta" (Query Workstation) command. If I find "Active" in the StdOut I run a function called GUI(). Gui() is just a window that covers the screen.

The problem seems to be that the whole program stops after I leave the program running for 45 minutes (or so) while I'm disconnected from the server.

I always find the program ended after running the Qwinsta command and reading StdOut. I don't know why.

Link to comment
Share on other sites

comparing an integer to a float(decimal) is OK, comparing a number to a string is a no-no.

Use this:

$idletimeout = 25000;Missed this before!

$line = StdoutRead($foo)
            If @error Then ExitLoop

From the help file:

Failure: Sets @error to non-zero if EOF is reached, STDOUT was not redirected for the process or other error.

Since you have the entire contents of Stdout, you're going to have reached EOF, so it's always going to set @error to a non-zero value.

You may want to do error checking in the original run command?

Also, I don't think you need @comspec /c

This:

Local $foo = Run("qwinsta " & $un & " /server:" & $cn, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)

should work, since qwinsta isn't an internal cmd command.

EDIT:

Actually, you might also want to do a check to wait for qwinsta to finish before processing the output.

$foo = Run("qwinsta " & $un & " /server:" & $cn, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
ProcessWaitClose($foo)
Edited by TurionAltec
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...