Jump to content

Search the Community

Showing results for tags 'wtsapi32'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. ..was looking for UserName from SessionID so I put this together #include <Debug.au3> ; for _DebugArrayDisplay() ; all you can get from _WTSQuerySessionInformation() Global $i = _WTSQuerySessionInformation(-1, 4) ; current user's SessionId Global $__a_WTS_INFO_CLASS = StringSplit("WTSInitialProgram,WTSApplicationName,WTSWorkingDirectory,WTSOEMId,WTSSessionId,WTSUserName," & _ "WTSWinStationName,WTSDomainName,WTSConnectState,WTSClientBuildNumber,WTSClientName,WTSClientDirectory,WTSClientProductId,WTSClientHardwareId," & _ "WTSClientAddress,WTSClientDisplay,WTSClientProtocolType,WTSIdleTime,WTSLogonTime,WTSIncomingBytes,WTSOutgoingBytes,WTSIncomingFrames," & _ "WTSOutgoingFrames,WTSClientInfo,WTSSessionInfo,WTSSessionInfoEx,WTSConfigInfo,WTSValidationInfo,WTSSessionAddressV4,WTSIsRemoteSession", ",", 2) For $n = 0 To UBound($__a_WTS_INFO_CLASS) -1 ConsoleWrite($n & @TAB & StringLeft($__a_WTS_INFO_CLASS[$n] & ' ________________', 24) & " " & _WTSQuerySessionInformation($i, $n, 1) & @CRLF) Next Global $a = ListUserSessions() _DebugArrayDisplay($a, "ListUserSessions()") Func ListUserSessions() ; mod. of https://www.autoitscript.com/forum/topic/139774-dllcall-and-returned-pointers/?do=findComment&comment=980850 Local $_Self_SessionId = _WTSQuerySessionInformation(-1, 4) ; -1 = current user ; 4 = WTSSessionId Local Enum $e_IsSelf_SessionId, $e_SessionName, $e_UserName, $e_SessionId, $e_StateName, $e_StateInt, $e_ClientName, $e_ClientIp, $e_Domain, $e_UBound Local Const $tagWTS_SESSION_INFO = 'dword SessionId;ptr WinStationName;uint State' Local $aResult = DllCall('wtsapi32.dll', 'int', 'WTSEnumerateSessionsW', 'ptr', 0, 'dword', 0, 'dword', 1, 'ptr*', 0, 'dword*', 0) If @error Or $aResult[0] = 0 Then Return SetError(1, 0, "") ; https://docs.microsoft.com/en-us/windows/desktop/api/wtsapi32/ne-wtsapi32-_wts_connectstate_class Local $aConnectionState = StringSplit("Active,Connected,ConnectQuery,Shadow,Disconnected,Idle,Listen,Reset,Down,Init", ",", 2) Local $tInfo, $Offset = 0, $c = 0, $aReturn[$aResult[5] + 1][$e_UBound] ; $e_UBound is the last enumerator, just to determine the size of the array $aReturn[0][$e_SessionId] = "ID" $aReturn[0][$e_SessionName] = "SessionName" $aReturn[0][$e_StateInt] = "StateInt" $aReturn[0][$e_StateName] = "State" $aReturn[0][$e_UserName] = "UserName" $aReturn[0][$e_ClientName] = "ClientName" $aReturn[0][$e_ClientIp] = "ClientIp" $aReturn[0][$e_Domain] = "Domain" For $i = 1 To $aResult[5] $tInfo = DllStructCreate($tagWTS_SESSION_INFO, $aResult[4] + $Offset) $Offset += DllStructGetSize($tInfo) $c += 1 $aReturn[$c][$e_SessionId] = DllStructGetData($tInfo, 'SessionId') $aReturn[$c][$e_SessionName] = DllStructGetData(DllStructCreate('wchar[1024]', DllStructGetData($tInfo, 'WinStationName')), 1) $aReturn[$c][$e_StateInt] = DllStructGetData($tInfo, 'State') If UBound($aConnectionState) > $aReturn[$c][$e_StateInt] Then $aReturn[$c][$e_StateName] = $aConnectionState[$aReturn[$c][$e_StateInt]] $aReturn[$c][$e_UserName] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 5) ; WTSUserName $aReturn[$c][$e_ClientName] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 10) ; WTSClientName $aReturn[$c][$e_ClientIp] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 14) ; WTSClientAddress $aReturn[$c][$e_Domain] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 7) ; WTSDomainName $aReturn[0][$e_IsSelf_SessionId] = $c If $_Self_SessionId = $aReturn[$c][$e_SessionId] Then $aReturn[$c][$e_IsSelf_SessionId] = 1 Else $aReturn[$c][$e_IsSelf_SessionId] = 0 EndIf Next DllCall('wtsapi32.dll', 'none', 'WTSFreeMemory', 'ptr', $aResult[4]) Return $aReturn EndFunc ;==>ListUserSessions Func _WTSQuerySessionInformation($SessionId, $WTSInfoClass = 10, $iReturnAsIs = 0) ; mod. of https://www.autoitscript.com/forum/topic/134679-get-hostname-of-the-client-connected-to-the-terminalserver-session/ Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformation", "Ptr", 0, "int", $SessionId, "int", $WTSInfoClass, "ptr*", 0, "dword*", 0) If @error Or $aResult[0] = 0 Then Return SetError(1, 0, "") Local $ip = DllStructGetData(DllStructCreate("byte[" & $aResult[5] & "]", $aResult[4]), 1) DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $aResult[4]) If $iReturnAsIs Then Return $ip Switch $WTSInfoClass ; https://docs.microsoft.com/en-us/windows/desktop/api/wtsapi32/ns-wtsapi32-_wts_client_address Case 4 ; WTSSessionId Return Int('0x' & StringTrimRight(StringReverse($ip), 3)) Case 14 ; WTSClientAddress If Not (Int(StringLeft($ip, 4)) = 2) Then ; IPv4 $ip = "" Else $ip = Dec(StringMid($ip, 15, 2)) & '.' & Dec(StringMid($ip, 17, 2)) & '.' & Dec(StringMid($ip, 19, 2)) & '.' & Dec(StringMid($ip, 21, 2)) EndIf EndSwitch Return StringReplace(BinaryToString($ip), Chr(0), "") EndFunc ;==>_GetWTSClientName
×
×
  • Create New...