-
Notifications
You must be signed in to change notification settings - Fork 0
/
Testuser2.au3
43 lines (36 loc) · 2.16 KB
/
Testuser2.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <Date.au3>
Global Const $tagWTS_SESSION_INFO = 'dword SessionId;ptr WinStationName;uint State'
$Ret = DllCall('wtsapi32.dll', 'int', 'WTSEnumerateSessionsW', 'ptr', 0, 'dword', 0, 'dword', 1, 'ptr*', 0, 'dword*', 0)
$Offset = 0
For $i = 1 To $Ret[5]
$tInfo = DllStructCreate($tagWTS_SESSION_INFO, $Ret[4] + $Offset)
$Offset += DllStructGetSize($tInfo)
;~ ConsoleWrite('SessionId: ' & DllStructGetData($tInfo, 'SessionId') & @CR)
;~ ConsoleWrite('WinStationName: ' & DllStructGetData(DllStructCreate('wchar[1024]', DllStructGetData($tInfo, 'WinStationName')), 1) & @CR)
;~ ConsoleWrite('State: ' & DllStructGetData($tInfo, 'State') & @CR)
;~ ConsoleWrite('--------------' & @CR)
$WinStationName=DllStructGetData(DllStructCreate('wchar[1024]', DllStructGetData($tInfo, 'WinStationName')), 1)
$SessionId=DllStructGetData($tInfo, 'SessionId')
$State=DllStructGetData($tInfo, 'State')
;~ if $WinStationName="RDP-Tcp" then
;~ if StringInStr($WinStationName,"RDP-Tcp")>0 AND StringInStr($WinStationName,"#")=0 then
if StringLen($WinStationName)=0 AND StringInStr($State,"4")>0 then
WriteLog( $SessionId & " - " & $WinStationName & " - " & DllStructGetData($tInfo, 'State'),"log1.txt",1)
;~ MsgBox(-1,"",DllStructGetData($tInfo, 'SessionId') & " - " & $WinStationName & " - " & DllStructGetData($tInfo, 'State'))
$RetSes = DllCall('wtsapi32.dll', 'int', 'WTSLogoffSession', "hwnd", 0, 'dword',DllStructGetData($tInfo, 'SessionId'),'bool', False)
;~ $RetSes = DllCall('wtsapi32.dll', 'int', 'WTSLogoffSession', "hwnd", 0, 'dword','3','bool', False)
WriteLog("@error "& @error & @CRLF & $SessionId & "- logoff: "& $RetSes[0],"log1.txt",1)
;~ WriteLog("@error "& @error & @CRLF & $SessionId & "- logoff: ","log1.txt",1)
;~ WriteLog(DllCall('wtsapi32.dll', 'DWORD', 'GetLastError'),"log1.txt",1)
;~ GetLastError
endif
Next
DllCall('wtsapi32.dll', 'none', 'WTSFreeMemory', 'ptr', $Ret[4])
Func WriteLog($Text,$NameLog,$Mode)
$Path="D:\"
$Time=_Date_Time_GetLocalTime()
$Time=_Date_Time_SystemTimeToDateTimeStr($Time)
$logfile = FileOpen($Path & $NameLog, $Mode)
FileWriteLine($logfile,$Time & "-" & $Text)
FileClose($logfile)
EndFunc