简体   繁体   English

在Windows中使用或不使用域登录用户名

[英]Getting logged on user's name with or without domain in Windows

Is there a direct API to get the currently logged in user's name with the domain? 是否有直接API可以获取域中当前登录的用户名? So, it would return something like "domain\\user\u0026quot; when a machine is on the domain, but at the same time it would return "user" when the machine is not on the domain? 那么,当机器在域中时,它将返回类似“ domain \\ user”的内容,但是同时当机器不在域中时,它将返回“用户”吗? If there's not, what's the best way to get this information? 如果没有,获取此信息的最佳方法是什么?

I noticed there's a LookupAccountName function - would that be the right direction to take? 我注意到有一个LookupAccountName函数-这是正确的方向吗?

Try GetUserNameEx() . 尝试GetUserNameEx() It supports various name formats. 它支持各种名称格式。

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

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