简体   繁体   English

Environment.UserName 为同一用户(外壳)提供不同的结果:替代/转换?

[英]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.

相关问题 Environment.UserName 作为 SYSTEM 而不是用户名返回 - Environment.UserName returning as SYSTEM rather than User's name Environment.UserName会在Windows 7,Windows 8.x和Windows 10中返回相同的结果吗? - Will Environment.UserName return the same result in Windows 7, Windows 8.x and Windows 10? Environment.UserName 返回应用程序池名称而不是用户名 - Environment.UserName returning application pool name instead of username 将app.config值设置为Environment.UserName - Set app.config value to Environment.UserName 我可以使用 Environment.Username 和 MYSQL 来验证登录吗? - Can I use Environment.Username and MYSQL to verify log in? 在 Windows 服务中使用时 Environment.UserName 会返回什么 - What would Environment.UserName return when used in a Windows Service 使用相同的参数进行加密可得出不同的结果 - Encryption with same parameters gives different results MVC助手,具有相同参数的方法会产生不同的结果 - MVC Helper, Method with same parameters gives different results 解析包含不同大小写的相同键的 JSON 字典 - Parsing a JSON dictionary that contains the same key with different casing 如果用户名相同(管理员),则DCOM身份“交互式用户”和“此用户”有什么区别? - What is different between DCOM Identity “The interactive user” and “This user” if the username is the same (Administrator)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM