Open vesnx opened 7 months ago
My sample would add an extra #0 to the end of the user name under windows, this fixes it
dwUserNameLen := cnMaxUserNameLen;
SetLength(sUserName, cnMaxUserNameLen);
if GetUserName(PChar(sUserName), dwUserNameLen) then
begin
// Subtract 1 to exclude the null terminator from the length
SetLength(sUserName, dwUserNameLen - 1);
end
else
// Handle the error case where GetUserName fails
SetLength(sUserName, 0);
Result := sUserName;
Thanks, i will update it.
I tested the GetLoggedUserName and found that it is possebly not implemented the right way as for me getlogin reurns a $0000000000000000 (empty string)
I left the original code , removed the cast error for UTF8ToString and look at the "GetEnvironmentVariable" for USER or LOGINNAME
This seems to reflect my user name on all system WSL, VM or physical
Perhaps you consider it in your update