Renz
Осваивающий
- Сообщения
- 63
- Репутация
- 37
Функция должна возвращать список пользователей на сервере(и не только) - аналог списка пользователей в диспетчере задач.
Но пока возвращает непайму что. :wacko: Может кто оценит своим трезвым взглядом?
Два дня на свадьбе не прошли даром :beer:
Код:
Но пока возвращает непайму что. :wacko: Может кто оценит своим трезвым взглядом?
Два дня на свадьбе не прошли даром :beer:
Код:
Код:
#include "WinAPI.au3"
Global Const $tag_SESSION_INFO = "dword SessionId;dword pWinStationName;dword WTS_CONNECTSTATE_CLASS"
Global Const $tag_WTSClientProtocolType = 16
Global Const $tag_WTSUserName = 5
;~ ************************************************
;~ BOOL WTSEnumerateSessions (
;~ __in HANDLE hServer,
;~ __in DWORD Reserved,
;~ __in DWORD версии,
;~ __out PWTS_SESSION_INFO * ppSessionInfo,
;~ __out DWORD * pCount
;~ );
;~ ------------------------------------------------
;~ typedef struct _WTS_SESSION_INFO {
;~ DWORD SessionId;
;~ LPTSTR pWinStationName;
;~ WTS_CONNECTSTATE_CLASS State;
;~ } WTS_SESSION_INFO, *PWTS_SESSION_INFO;
;~ ************************************************
Func __WTSEnumerateSessions()
Local $hServer = _WTSOpenServer ()
Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSEnumerateSessions", "HANDLE", $hServer, "dword", 0, "dword", 1, _
"ptr*", 0, "dword*", 0)
If @error Then Return MsgBox(0,"Error",@error)
Local $iCount = $aResult[5]
Local $aInfo[$iCount + 1][3]
$aInfo[0][0] = $iCount
If $aResult[0] <> 0 Then
Local $pInfo = $aResult[4]
Local $tInfo
For $iI = 1 To $iCount-1
$tInfo = DllStructCreate($tag_SESSION_INFO, $pInfo)
if @error Then
MsgBox(0,"","Error in DllStructCreate " & @error);
exit
endif
$aInfo[$iI][0] = DllStructGetData($tInfo, "SessionId")
$aInfo[$iI][1] = _WinAPI_WideCharToMultiByte(DllStructGetData($tInfo, "pWinStationName"))
$aInfo[$iI][2] = DllStructGetData($tInfo, "WTS_CONNECTSTATE_CLASS")
$pInfo += DllStructGetSize($tInfo)
MsgBox(0,"SESSION_INFO",$aInfo[$iI][0]&"|"&$aInfo[$iI][1]&"|"&$aInfo[$iI][2])
Next
EndIf
__WTSFreeMemory($aResult[4])
_WTSCloseServer ($hServer)
Return SetExtended($aResult[0], $aInfo)
EndFunc ;==> _WTSEnumerateSessions
Func _WTSOpenServer ($sServer = "")
If $sServer = "" Then $sServer = @ComputerName
Local $aResult = DllCall("Wtsapi32.dll", "HANDLE", "WTSOpenServerA", "str", $sServer)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[0]
EndFunc ;==>_WTSOpenServer
Func _WTSCloseServer ($hServer)
Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSCloseServer", "HANDLE", $hServer)
If @error Then Return MsgBox(0,"Error",@error)
EndFunc ;==>_WTSCloseServer
Func __WTSFreeMemory($pBuffer)
Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $pBuffer)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0]
EndFunc ;==>__WTSFreeMemory
;~ BOOL WTSQuerySessionInformation(
;~ __in HANDLE hServer,
;~ __in DWORD SessionId,
;~ __in WTS_INFO_CLASS WTSInfoClass,
;~ __out LPTSTR *ppBuffer,
;~ __out DWORD *pBytesReturned
;~ );
Func _WTSQuerySessionInformation($aInfo)
Local $hServer = _WTSOpenServer ()
Local $iCount = $aInfo[0][0]
Local $aInfoSes[$iCount][2]
$aInfoSes[0][0] = $iCount
For $iI =1 To $iCount
$sSessionId = $aInfo[$iI][0]
Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformation", "HANDLE", $hServer, "dword", $sSessionId, _
"int", $tag_WTSUserName, "dword*", 0, "dword*", 0 )
If @error Then Return MsgBox(0,"Error",@error)
$aInfoSes[$iI][0] = $aResult[4]
MsgBox(0,"Name",$aResult[4])
Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformation", "HANDLE", $hServer, "dword", $sSessionId, _
"int", $tag_WTSClientProtocolType, "dword*", 0, "dword*", 0 )
If @error Then Return MsgBox(0,"Error",@error)
$aInfoSes[$iI][1] = $aResult[4]
MsgBox(0,"ClientProtocol",$aResult[4])
Next
_WTSCloseServer ($hServer)
Return SetExtended($aResult[0], $aInfoSes)
EndFunc
_WTSQuerySessionInformation(__WTSEnumerateSessions())