开发者

Why does changing %USERPROFILE% cause sHGetFolderPath SIDL_APPDATA to fail?

开发者 https://www.devze.com 2023-01-27 07:52 出处:网络
I\'m trying to debug an issue with Cabal where it won\'t work if I change the value of the %USERPROFILE% environment variable prior to running it.I seem to have traced the error back to the win32 call

I'm trying to debug an issue with Cabal where it won't work if I change the value of the %USERPROFILE% environment variable prior to running it. I seem to have traced the error back to the win32 call sHGetFolderPath pointing at SIDL_APPDATA, which seems to fail if that variable is modified.

I'm not really sure where to go from here though. Why is that call breaking? Why doesn't changing that env-var just point the user directory elsewhere? (I'm trying to get cabal to work cleanly from a flash drive.)

On the same subject, calls to the same function with SIDL_PROFILE returns my actual (logged in) user directory (C:/Docs and Settings/Me), even though the console running GHCi had every env-var I could find with a user directory in it reset to the flash drive. Do thos开发者_JAVA技巧e Win32 calls just completely ignore the environment variables?


Win32 functions doesn't use environment variables for that, that information is stored in other locations. The exact location is not important since Microsoft consider that implementation details, so it can change from version to version (The long and sad story of the Shell Folders key).

%USERPROFILE% and similar environment variables are provided by the command line processor as a courtesy for writing batch files, so you can get that locations directly from a script. Changing the environment variable will only affect scripts, or a rare app that check that variables instead of using SHGetSpecialFolderPath or similar functions (which is the recommended method for Win32 applications).

Long story sort: you can't change the location of user folders on a per-application basis.

0

精彩评论

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

关注公众号