为什么更改 %USERPROFILE% 会导致 sHGetFolderPath SIDL_APPDATA 失败?

发布于 2024-10-04 10:54:55 字数 368 浏览 0 评论 0原文

我正在尝试调试 Cabal 的一个问题,如果我在运行之前更改 %USERPROFILE% 环境变量的值,它将无法工作。我似乎已将错误追溯到指向 SIDL_APPDATA 的 win32 调用 sHGetFolderPath,如果修改该变量,该调用似乎会失败。

但我不太确定从这里该去哪里。为什么这个通话会中断?为什么更改该环境变量不只是将用户目录指向其他地方? (我试图让 cabal 从闪存驱动器干净地工作。)

在同一主题上,使用 SIDL_PROFILE 调用同一函数会返回我的实际(登录)用户目录(C:/Docs and Settings/Me),甚至尽管运行 GHCi 的控制台具有我能找到的每个环境变量,其中的用户目录重置为闪存驱动器。这些 Win32 调用是否完全忽略环境变量?

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 those Win32 calls just completely ignore the environment variables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

所谓喜欢 2024-10-11 10:54:55

Win32 函数不使用环境变量,该信息存储在其他位置。确切的位置并不重要,因为 Microsoft 考虑了实现细节,因此它可以根据版本进行更改 (Shell 文件夹键漫长而悲伤的故事)。

%USERPROFILE% 和类似的环境变量由命令行处理器提供,作为编写批处理文件的礼貌,因此您可以直接从脚本获取这些位置。更改环境变量只会影响脚本,或者很少有应用程序检查变量,而不是使用 SHGetSpecialFolderPath 或类似函数(这是 Win32 应用程序的推荐方法)。

长话短说:您无法根据每个应用程序更改用户文件夹的位置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文