Enumerates all of the processes that exist on the specified terminal server.
wtsEnumProcesses(server[,session [, virtualization host]])
(s) server This is the name of the terminal server system for which processes 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) session [optional] This is a session id value. If this parameter is omitted or is specified as an empty string then it defaults to a value of negative one [-1], which means that processes for all sessions are to be enumerated. If any other valid session id value is passed in for the value of this parameter then the processes that get enumerated will be restricted to only those processes which belong to the specified session id.
(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 returns truncated process names instead of the executable's full file name. This parameter requires Windows 7/2008 (or newer) and is ignored on older systems.
(a) Returns a single dimensional array containing process 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 processes 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 processes on either the local system or on a remote terminal server system. The process id values that get returned by this function can be limited to those that are for processes that belong to a specific session id.
The return value is an array with a single dimension. The array contains the following information:
(i) Result[0] = Process 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] = Process Id # list. This is a @TAB delimited list of process id numbers.
(s) Result[2] = Process Name list. This is a @TAB delimited list of process names.
(s) Result[3] = Session Id # list. This is a @TAB delimited list of session id numbers.
(s) Result[4] = SID list. This is a @TAB delimited list of SID string values that are associated with the user that is logged in for each process.
The @TAB delimited lists are structured so that each of the lists contains different types of information for the same process # at the same element in each list.
The process id values are compatible for use with the Process Extender.
The SID string values may be converted into account names by using the functions that are available in the Win32 Network Extender for Windows NT/2K/XP.
;Load 32-bit or 64-bit extender AddExtender( "WWWTS44I.DLL" , 0, "WWWTS64I.DLL" ) Title01 = 'Test wtsEnumProcesses()' ; Get all of the processes on the system. ErrorMode(@OFF) Result = wtsEnumProcesses('') RC = LastError() ErrorMode(@CANCEL) TempMsg = StrCat('wtsEnumProcesses("") RC = ',RC,@CRLF) If (RC == 0) TempMsg = StrCat(TempMsg,@CRLF,'Total # of Processes = ',Result[0]) TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Process ID''s = "',StrReplace(Result[1],@TAB,','),'"') TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Process Names = "',StrReplace(Result[2],@TAB,','),'"') TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Session #''s = "',StrReplace(Result[3],@TAB,','),'"') TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'User SID''s = "',StrReplace(Result[4],@TAB,','),'"') EndIf Message(Title01,TempMsg) ; Now we get processes only for our own session id. TempPID = DllCall('KERNEL32.DLL',long:'GetCurrentProcessId') TempSessId = wtsProcIdToSessId(TempPID) ErrorMode(@OFF) Result = wtsEnumProcesses('',TempSessId) RC = LastError() ErrorMode(@CANCEL) TempMsg = StrCat('wtsEnumProcesses("",',TempSessId,') RC = ',RC,@CRLF) If (RC == 0) TempMsg = StrCat(TempMsg,@CRLF,'Total # of Processes = ',Result[0]) TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Process ID''s = "',StrReplace(Result[1],@TAB,','),'"') TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Process Names = "',StrReplace(Result[2],@TAB,','),'"') TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'Session #''s = "',StrReplace(Result[3],@TAB,','),'"') TempMsg = StrCat(TempMsg,@CRLF,@CRLF,'User SID''s = "',StrReplace(Result[4],@TAB,','),'"') EndIf Message(Title01,TempMsg) Exit