Hi, Avory -
You'll need two external function declarations, one for each of the two Windows API functions that will need to be called. If you have never declared and used an external function, here is some online help that may help (it's for PB 2022 R3, but external function declarations work the same in PB 12.5):
https://docs.appeon.com/pb2022r3/application_techniques/Using_external_functions.html#Declaring_external_functions
Define the two external function declarations in the window or user object that will be finding and setting these two values:
FUNCTION Boolean GetComputerName ( &
REF String lpBuffer, &
REF UnsignedLong nSize &
) LIBRARY "kernel32.dll" ALIAS FOR "GetComputerNameW"
FUNCTION Boolean GetUserName ( &
REF String lpBuffer, &
REF UnsignedLong nSize &
) LIBRARY "advapi32.dll" ALIAS FOR "GetUserNameW"
Create a window/object function to invoke each API function:
// Function of_GetComputerName() Returns String
// No. of characters (not including the terminating null).
Constant UnsignedLong MAX_COMPUTERNAME_LENGTH = 31
Boolean lb_rc
ULong lul_size
String ls_name
// Pre-allocate space in a string that will receive the computer's name
lul_size = MAX_COMPUTERNAME_LENGTH
ls_name = Space(lul_size)
lul_size = lul_size + 1 // Add 1 for the null character that ends each string.
// Obtain the name of the computer via a Windows API function.
// This API function returns True if successful.
lb_rc = This.GetComputerName(ls_name,lul_size)
If Not lb_rc Then
Return ''
End If
Return ls_name
// Function of_GetUserName() Returns String
// No. of characters (not includeing the terminating null) in the user's name.
Constant UnsignedLong MAX_USERNAME_LENGTH = 255
boolean lb_rc
ulong lul_size = MAX_USERNAME_LENGTH
string ls_name
// Pre-allocate space in a string that will receive the user's ID/name.
ls_name = Space(lul_size)
lul_size = lul_size + 1 // Add 1 for the null character that ends each string.
// Obtain the user's name via a Windows API function.
// This API function returns True if successful.
lb_rc = This.GetUserName(ls_name,lul_size)
If Not lb_rc Then
Return ""
End If
Return ls_name
Best regards, John
And, in order to manage expectations, I will let you know now that I cannot write the code for you... that is NOT what we do here. A code snippet (like what was provided earlier to illustrate a point or technique) is one thing and I was happy to provide that in my previous response, but coding solutions for you is what paid consultants are for.