本帖最后由 非典男人 于 2012-2-21 14:13 编辑
以下代码运行后的效果图,请问如何将数组中指定的内容单独显示或者发送给变量赋值,谢谢.
同时有个新的问题,就是在 通过mstsc连接服务器时如何实现获取客户端计算机的IP地址,
以下代码是pusofalse提供, 已经可以获得 客户端计算机名,但是无法获取到客户端计算机的IP地址.感谢pusofalse的帮助.
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_UseX64=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <Array.au3>
Dim $hServer
Const $tagWTS_SESSION_INFO = "long SessionID;ptr SessionName;long State"
Func _WTSEnumSessions($hServer)
Local $iResult
$iResult = DllCall("Wtsapi32.dll", "bool", "WTSEnumerateSessionsW", "handle", $hServer, "long", 0, "long", 1, "ptr*", 0, "long*", 0)
Local $aResult[$iResult[5] + 1][7] = [[$iResult[5]]]
TCPStartup()
For $i = 1 To $aResult[0][0]
$tSessionInfo = DllStructCreate($tagWTS_SESSION_INFO, $iResult[4] + ($i - 1) * (@AutoItX64 + 1) * 12)
$aResult[$i][0] = DllStructGetData($tSessionInfo, "SessionID")
$aResult[$i][1] = DllStructGetData($tSessionInfo, "State")
$aResult[$i][2] = _WTSReadStringW( DllStructGetData($tSessionInfo, "SessionName"), 0)
$aResult[$i][3] = _WTSReadStringW(_WTSQuerySessionData($hServer, $aResult[$i][0], 7)) ; Domain name
; $aResult[$i][4] = _WTSReadStringW(_WTSQuerySessionData($hServer, $aResult[$i][0], 5)) ; User name
$aResult[$i][5] = _WTSReadStringW(_WTSQuerySessionData($hServer, $aResult[$i][0], 10)) ; Client name
$aResult[$i][6] = _GetHostIPAddresses($aResult[$i][3])
Next
DllCall("Wtsapi32.dll", "none", "WTSFreeMemory", "ptr", $iResult[4])
Return $aResult
EndFunc ;==>_WTSEnumSessions
Func _WTSReadStringW($pStringW, $fFree = 1)
If $pStringW = 0 Then Return ""
Local $iResult
$iResult = DllCall("Kernel32.dll", "long", "lstrlenW", "ptr", $pStringW)
$iResult = DllCall("Kernel32.dll", "none", "RtlMoveMemory", "wstr", "", "ptr", $pStringW, "long", $iResult[0] * 2 + 2)
If $fFree Then DllCall("Wtsapi32.dll", "none", "WTSFreeMemory", "ptr", $pStringW)
Return $iResult[1]
EndFunc ;==>_WTSReadStringW
Func _WTSQuerySessionData($hServer, $iSessionID, $iInfoClass)
Local $iResult
$iResult = DllCall("Wtsapi32.dll", "bool", "WTSQuerySessionInformationW", "ptr", $hServer, "long", $iSessionID, "long", $iInfoClass, "ptr*", 0, "long*", 0)
Return SetError(0, $iResult[5], $iResult[4])
EndFunc ;==>_WTSQuerySessionData
Func _GetHostIPAddresses($sHostName)
Local $iResult
$iResult = DllCall("Ws2_32.dll", "ptr", "gethostbyname", "str", $sHostName)
If $iResult[0] = 0 Then Return ""
Local $tHostent = DllStructCreate("ptr name;ptr aliases;word addrtype;word length;ptr addrlist", $iResult[0])
Local $pAddrList = DllStructGetData($tHostent, "addrlist")
Local $tAddress, $pAddress, $tLONG, $iResult, $sResult
For $i = 0 To 1023
$tAddress = DllStructCreate("ptr address", $pAddrList + $i * ((@AutoItX64 + 1) * 4))
$pAddress = DllStructGetData($tAddress, "address")
If $pAddress = 0 Then ExitLoop
$tLONG = DllStructCreate("long LONG", $pAddress)
$iResult = DllCall("Ws2_32.dll", "str", "inet_ntoa", "long", DllStructGetData($tLONG, "LONG"))
$sResult &= $iResult[0] & ", "
Next
Return StringTrimRight($sResult, 2)
EndFunc ;==>_GetHostIPAddresses
$aSession = _WTSEnumSessions(0)
_ArrayDisplay($aSession)
|