#include <Array.au3>
Global Const $WTS_CURRENT_SERVER_HANDLE = 0
$aData = WTSEnumerateSessionsEx()
_ArrayDisplay($aData, 'Массив текущих сессий', Default, Default, Default, Default, '№|ExecEnvId|State|SessionId|SessionName|HostName|UserName|DomainName|FarmName')
Func WTSEnumerateSessionsEx($hServer = $WTS_CURRENT_SERVER_HANDLE)
Local $aRet = DllCall('Wtsapi32.dll', 'BOOL', 'WTSEnumerateSessionsEx', 'HANDLE', $hServer, 'DWORD*', 1, 'DWORD', 0, 'PTR*', 0, 'DWORD*', 0)
If @error Or Not IsArray($aRet) Or $aRet[0] = 0 Then Return SetError(1, 0, 0)
Local $Offset = 0, $tInfo
Local Const $TAG_WTS_SESSION_INFO_1 = 'DWORD ExecEnvId;uint State;DWORD SessionId;PTR SessionName;PTR HostName;PTR UserName;PTR DomainName;PTR FarmName;'
Local Enum $iExecEnvId, $iState, $iSessionId, $iSessionName, $iHostName, $iUserName, $iDomainName, $iFarmName, $iLAST
Local $aOut[$aRet[5]][$iLAST] ;Выходной массив
For $i = 1 To $aRet[5]
$tInfo = DllStructCreate($TAG_WTS_SESSION_INFO_1, $aRet[4] + $Offset)
$Offset += DllStructGetSize($tInfo)
$aOut[$i - 1][$iExecEnvId] = DllStructGetData($tInfo, 'ExecEnvId')
$aOut[$i - 1][$iState] = DllStructGetData($tInfo, 'State')
$aOut[$i - 1][$iSessionId] = DllStructGetData($tInfo, 'SessionId')
$aOut[$i - 1][$iSessionName] = DllStructGetData(DllStructCreate("char[" & 1024 & "]", DllStructGetData($tInfo, 'SessionName')), 1)
$aOut[$i - 1][$iHostName] = DllStructGetData(DllStructCreate("char[" & 1024 & "]", DllStructGetData($tInfo, 'HostName')), 1)
$aOut[$i - 1][$iUserName] = DllStructGetData(DllStructCreate("char[" & 1024 & "]", DllStructGetData($tInfo, 'UserName')), 1)
$aOut[$i - 1][$iDomainName] = DllStructGetData(DllStructCreate("char[" & 1024 & "]", DllStructGetData($tInfo, 'DomainName')), 1)
$aOut[$i - 1][$iFarmName] = DllStructGetData(DllStructCreate("char[" & 1024 & "]", DllStructGetData($tInfo, 'FarmName')), 1)
Next
;Освобождаем буфер
Local Const $WTSTypeSessionInfoLevel1 = 2 ;??? не уверен
DllCall('Wtsapi32.dll', 'BOOL', 'WTSFreeMemoryEx', 'UINT', $WTSTypeSessionInfoLevel1, 'PTR', $aRet[4], 'ULONG', $aRet[5])
Return SetError(0, 0, $aOut)
EndFunc ;==>WTSEnumerateSessionsEx