简体   繁体   English

在Windows上获取当前的用户名

[英]Get current username on windows

I modified my username in Control Panel -> User Accounts -> Change Your Name. 我在控制面板->用户帐户->更改名称中修改了用户名。

But when I use the GetUserName function, it returned my old username. 但是当我使用GetUserName函数时,它返回了我的旧用户名。

How do I get the new one? 如何获得新的?

EDIT 1 编辑1

Here's the code as requested: 这是要求的代码:

char user[UNLEN + 1];
DWORD user_len = UNLEN + 1;
GetUserName(user, &user_len);

Try to use the API GetUserNameEx , and passing as a format NameDisplay . 尝试使用API GetUserNameEx ,并以NameDisplay格式NameDisplay I guess you changed the display name of the user, not the logon name. 我猜您更改了用户的显示名称,而不是登录名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM