From 6e4de3e9f1292b4a6ec9e55f63539a7a6787d74c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 15 Apr 2026 19:54:37 +0800 Subject: [PATCH] Platform (Windows): uses `LsaGetUserName` to acquire user name --- src/common/impl/FFPlatform_windows.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/impl/FFPlatform_windows.c b/src/common/impl/FFPlatform_windows.c index b4ed2b1ce..170494db8 100644 --- a/src/common/impl/FFPlatform_windows.c +++ b/src/common/impl/FFPlatform_windows.c @@ -139,9 +139,15 @@ static void getUserName(FFPlatform* platform) { ffStrbufSetWS(&platform->fullUserName, buffer); } - size = ARRAY_SIZE(buffer); - if (GetUserNameW(buffer, &size)) { // GetUserNameExW(10002)? - ffStrbufSetWS(&platform->userName, buffer); + NTSYSAPI NTSTATUS NTAPI LsaGetUserName( + _Outptr_ PLSA_UNICODE_STRING* UserName, + _Outptr_opt_ PLSA_UNICODE_STRING* DomainName + ); + PLSA_UNICODE_STRING userName = NULL; + if (NT_SUCCESS(LsaGetUserName(&userName, NULL))) { + ffStrbufSetNWS(&platform->userName, userName->Length / sizeof(wchar_t), userName->Buffer); + RtlFreeUnicodeString(userName); + LsaFreeMemory(userName); } else { ffStrbufSetS(&platform->userName, getenv("USERNAME")); }