2011-01-07 107 views
2

我遇到了路徑壓縮問題。我正在讀取註冊表值,例如%USERPROFILE%\ AppData \ Roaming。我遇到的問題是不斷擴展到C:\ Users \ John \ AppData \ Roaming的路徑。 我知道環境擴展,但我不想使用它,以防將來遇到路徑壓縮問題。我使用的代碼是:C#路徑壓縮問題

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")); 

任何建議是值得歡迎的。謝謝。

回答

2

有一個overloaded GetValue method,你可以打電話,你不能指定擴大環境變量:

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

謝謝!我正在瀏覽重載的方法,但我想我忽略了它。完美的作品! – 2011-01-07 19:29:49