开发者

C# Path Compression Issue

开发者 https://www.devze.com 2023-02-03 06:50 出处:网络
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:\

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.


There's an overloaded GetValue method that you can call where you can specify not to expand environment variables:

hkUsersPath.GetValue("AppData", null, RegistryValueOptions.DoNotExpandEnvironmentNames);
0

精彩评论

暂无评论...
验证码 换一张
取 消