Jump to content

hamster

Members
  • Posts

    5
  • Joined

  • Last visited

Profile Information

  • Location
    Slovenia

hamster's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. If this helps anyone, I'm currently using the code below to get the results from "query user" into array. Tested on English versions of Windows 2003 Server Standard SP2, Windows Server 2008 Enterprise R2, Windows 7. #include <Constants.au3> #include <Array.au3> Opt("MustDeclareVars", 1) Local $users = _QueryUser() If Not @error Then _ArrayDisplay($users) Else MsgBox(48, 'Error', $users) EndIf Func _QueryUser() Local $line, $lines, $return Local $runPID = Run(@ComSpec & " /c query useur", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Do $line = StdoutRead($runPID) If $line Then $lines &= $line Until @error If $lines Then $lines = StringSplit(StringTrimRight(StringReplace(StringRegExpReplace($lines, "(rn)|r|n|(nr)", "|"), ">", ""),1), "|") Local $data[$lines[0]][6] ;Field lengths: (1+)22, 19, 4, 8, 11, the rest For $i = 0 To $lines[0]-1 Step 1 StringStripWS($lines[$i+1], 3) $data[$i][0] = StringStripWS(StringLeft($lines[$i+1], 22), 3) $data[$i][1] = StringStripWS(StringLeft(StringTrimLeft($lines[$i+1], 22), 19), 3) $data[$i][2] = StringStripWS(StringLeft(StringTrimLeft($lines[$i+1], 22+19), 4), 3) $data[$i][3] = StringStripWS(StringLeft(StringTrimLeft($lines[$i+1], 22+19+4), 8), 3) $data[$i][4] = StringStripWS(StringLeft(StringTrimLeft($lines[$i+1], 22+19+4+8), 11), 3) $data[$i][5] = StringStripWS(StringTrimLeft($lines[$i+1], 22+19+4+8+11), 3) Next $return = $data SetError(0) Else Do $line = StderrRead($runPID) If $line Then $lines &= $line Until @error $return = String($lines) SetError(1) EndIf Return($return) EndFunc This code is far from ideal, and I'm still looking for a better way to get this information, especially user's idle time. Edit: made the code more pretty
  2. So, here's my problem: My script is running as Windows service and must every second or so get idle time of a specific user logged on via Remote Desktop. I didn't have any problem getting current user's idle time (in this case, the "current user" is SYSTEM), however I found getting another user's idle time to be very difficult. I imagine one way would be to write output of "query user" to a file and read from it, but I'd really like to avoid unnecessary writing on disk. Another way would be to run a separate script in each user's context and program it to report idle time back to the main script. I don't like this option too - too messy, too many unnecessary processes running. I found this interesting and 90% undocumented function named WinStationQueryInformationW. Here someone got the results I want from it, but it's written in C... I tried to "translate" that into AutoIT language, but I don't really have enough knownledge in this area. Is there anybody out there who could help me to make use of that function? I'm also looking for alternatives...
  3. Sorry for bringing up this topic, but I went through every single post and I still cannot find a single working download link. It will be much appreciated if somebody (re)uploads this UDF somewhere.
  4. Nice code, also very CPU friendly... However, I think I found a bug. When there is connected more than one client and one of the clients becomes inactive for the timeout period, the Cleanup() function results in the following error:
×
×
  • Create New...