KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Window User List
PRODUCT: 4D | VERSION: 16 | PLATFORM: Win
Published On: June 8, 2018

Below is a utility method to obtain the list of Windows Users on the System.

// Method: Util_WinGetUsersList
//
// Parameters:
// $1 - Pointer to Text Array to Recieve Results
//
// ---------------------------------------------------

C_POINTER($1)

C_TEXT($lepI_t)
C_TEXT($lepO_t)
C_TEXT($lepErr_t)
C_BOOLEAN($match_b)
C_BOOLEAN($end_b)
ARRAY TEXT($users_at;0)

SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true")
LAUNCH EXTERNAL PROCESS("net user";$lepI_t;$lepO_t;$lepErr_t)
$match_b:=Match regex("\r\n\r\n-+\r\n";$lepO_t;1;$posFound_l;$lenFound_l)
$list_t:=Substring($lepO_t;$posFound_l+$lenFound_l)
$list_t:=Replace string($list_t;"\r\n";"")


While ($end_b=False)
    $user_t:=Substring($list_t;1;25)
    $user_t:=Replace string($user_t;" ";"")
    APPEND TO ARRAY($users_at;$user_t)
    $list_t:=Substring($list_t;26)
   
    //Exit Condition
    If ($list_t="The command completed successfully.")
       $end_b:=True
    End if
   
End while

COPY ARRAY($users_at;$1->)


Example of using the method:
ARRAY TEXT($res_at;0)
Util_WinGetUSerList(->$res_at)