C# 路径压缩问题
我遇到了路径压缩问题。我正在读取注册表值,例如 %USERPROFILE%\AppData\Roaming。我遇到的问题是它不断将路径扩展到 C:\Users\John\AppData\Roaming。 我知道环境扩展,但我不想使用它,以防将来遇到路径压缩问题。我使用的代码是:
RegistryKey hkUsersPath = Registry.Users.OpenSubKey(@".DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\");
DefaultAppData = Convert.ToString(hkUsersPath.GetValue("AppData"));
if (hkUsersPath.GetValue("AppData") == null)
DefaultAppData = Convert.ToString(hkUsersPath.GetValue("APPDATA"));
欢迎任何建议。谢谢。
I'm having an issue with path compression. I'm reading a registry value, such as %USERPROFILE%\AppData\Roaming. The problem I'm having is it keeps expanding the the path out to C:\Users\John\AppData\Roaming.
I know about Environment Expand, but I don't want to use that in case I have an path compression issue in the future. The code I'm using is:
RegistryKey hkUsersPath = Registry.Users.OpenSubKey(@".DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\");
DefaultAppData = Convert.ToString(hkUsersPath.GetValue("AppData"));
if (hkUsersPath.GetValue("AppData") == null)
DefaultAppData = Convert.ToString(hkUsersPath.GetValue("APPDATA"));
Any advice is welcome. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个重载的 GetValue 方法,您可以在其中指定不调用该方法展开环境变量:
There's an overloaded GetValue method that you can call where you can specify not to expand environment variables: