[英]Environment.UserName gives different results for same user (casing): alternative/transformation?
The .NET call Environment.UserName
for the most part (>99.9% of the time) gives usernames in the same casing - for example Awebb
. .NET 在大多数情况下(>99.9% 的时间)调用
Environment.UserName
提供相同大小写的用户名 - 例如Awebb
。 Occasionally though I'm seeing AWebb
.虽然我偶尔会看到
AWebb
。 Sometimes it seems that it relates the username as the user entered it when logging on, but other times this is confirmed as not the case.有时,它似乎与用户在登录时输入的用户名相关,但有时这被证实并非如此。
I think this is bad design and a username should be a username, correctly-cased, no matter what: if the user decides to enter aWEbb
then that doesn't mean the OS should start telling apps that that's their username.我认为这是一个糟糕的设计,用户名应该是正确大小写的用户名,无论如何:如果用户决定输入
aWEbb
,那么这并不意味着操作系统应该开始告诉应用程序这是他们的用户名。
That aside, what's the best/other way to obtain the current user's username - ideally without any domain - using the same security permissions required for Environment.UserName
?除此之外,使用
Environment.UserName
所需的相同安全权限获取当前用户的用户名(理想情况下没有任何域)的最佳/其他方式是什么? I know I could normalise everything to lowercase/uppercase but I'm really after obtaining the username correctly capitalised/formatted.我知道我可以将所有内容规范化为小写/大写,但我真的在获得正确大写/格式化的用户名之后。
Get the name of their profile folder:获取他们的个人资料文件夹的名称:
SHGetKnownFolderPath(FOLDERID_Profile, 0, 0, &s);
eg C:\Users\KJohnstone
例如
C:\Users\KJohnstone
It seems this is simply not possible.看来这根本不可能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.