[英]Environment.UserName returning as SYSTEM rather than User's name
I've been using我一直在用
Environment.UserName
To display the current user's name and it's been working all this time.显示当前用户的名称,并且一直在工作。
However, started working on my project today - Environment.UserName
has returned the word "SYSTEM"
despite the user name still being the same as it was before.但是,今天开始处理我的项目 - 尽管用户名仍然与以前相同,但Environment.UserName
返回了"SYSTEM"
一词。
Happened to us too 3 days ago, we were reaching the documents and settings via Environment.UserName
(i guess it was a windows update) 3 天前也发生在我们身上,我们通过Environment.UserName
文档和设置(我猜这是 Windows 更新)
We solved it by using %USERPROFILE% instead of Environment.UserName
in the string.我们通过在字符串中使用 %USERPROFILE% 而不是Environment.UserName
来解决它。
readonly string savedFilesDirectoryPath =
Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Documents\OurProjectName");
%USERPROFILE% env var on windows indicates where a user home directory is located in the file system Windows 上的 %USERPROFILE% env var 指示用户主目录在文件系统中的位置
For your exact question tho: I think in build mode your solution will work actually so try that对于您的确切问题:我认为在构建模式下,您的解决方案实际上会起作用,因此请尝试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.