Enumerates all of the terminal server sessions that exist on the specified server.
wtsEnumSessions(server[, virtualization host])
(s) server: This is the name of the terminal server system for which sessions should be enumerated. The server name should have the leading "\\" characters on it. Passing in an empty string for this parameter will cause the local terminal server system to be used.
(i) virtualization-host [optional] Enables access to Remote Desktop Virtualization Hosts. If this parameter is omitted or is specified as an empty string then it defaults to a zero [0], which means the function will only be able to access Remote Desktop Session Hosts. If any other valid number is used for the value of this parameter then the function will be able to access both Remote Desktop Virtualization Hosts and Remote Desktop Session Hosts. Note that when this parameter is set to a number other than zero the function may not return system created sessions like the rdp-tcp session. This parameter requires Windows 7/2008 (or newer) and is ignored on older systems.
(a) Returns a single dimensional array containing session information. Refer to the "Notes:" section for more information about the format of the data in the array.
This function will enumerate [e.g. list] all of the terminal services sessions that exist on the specified terminal server system. The script that calls this function must be running on a terminal server system in order to gather information for sessions on either the local system or on a remote terminal server system.
The return value is an array with a single dimension. The array contains the following information:
(i) Result[0] = Session Count. This is the count of the # of items in the @TAB delimited lists that are contained in the rest of the array's elements.
(s) Result[1] = Session Id # list. This is a @TAB delimited list of session id numbers.
(s) Result[2] = Session Name list. This is a @TAB delimited list of session names.
(s) Result[3] = Connection State list. This is a @TAB delimited list of connection states for all of the sessions.
The following connection state values are defined:
"ACTIVE"
"CONNECTED"
"CONNECTQUERY"
"SHADOW"
"DISCONNECTED"
"IDLE"
"LISTEN"
"RESET"
"DOWN"
"INIT"
"*UNKNOWN*"
The @TAB delimited lists are structured so that each of the lists contains different types of information for the same session # at the same element in each list.
;Load 32-bit or 64-bit extender AddExtender( "WWWTS44I.DLL" , 0, "WWWTS64I.DLL" )
Title01 = 'Test wtsEnumSessions()' ErrorMode(@OFF) Result = wtsEnumSessions('') RC = LastError() ErrorMode(@CANCEL) TempMsg = StrCat('wtsEnumSessions("") RC = ',RC,@CRLF) If (RC == 0) TempMsg = StrCat(TempMsg,@CRLF,'Total # of Sessions = ',Result[0]) TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Session #''s = "',StrReplace(Result[1],@TAB,', '),'"') TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Session Names = "',StrReplace(Result[2],@TAB,', '),'"') TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Connection Statuses = "',StrReplace(Result[3],@TAB,', '),'"') EndIf Message(Title01,TempMsg) Exit