是否有API可以获取操作系统中定义的原始变量值

发布于 2024-12-23 08:27:11 字数 556 浏览 3 评论 0原文

在 Windows 系统属性 |环境变量,有一个变量“AppStatus=status1”

有一个名为 MyApp.exe 的 exe。在实现中,它用代码更改变量。

int ret = putenv("AppStatus=status2"); // Change the environment variable.

如果使用API​​ char * pStatus = getenv("AppStatus");,则返回值为"status2"

我想要得到的是操作系统中定义的原始值(“AppStatus=status1”)而不是进程块中定义的值。为了实现这一点,我可以查询注册表项

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path。

不过如果有API支持的话应该会更好。有人知道吗?

In the Windows System Properties | Environment Variables, there is a variable "AppStatus=status1".

There is an exe named MyApp.exe. In the implementation it changes the variable with the code.

int ret = putenv("AppStatus=status2"); // Change the environment variable.

If use API char * pStatus = getenv("AppStatus");, the returned value is "status2".

What I want to get is the original value defined in the OS ("AppStatus=status1") not in the process block. To implement this I can query the registry key

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path.

But it should be better if there is an API that supports it. Is anybody aware of it?

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

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

发布评论

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

评论(1

爱她像谁 2024-12-30 08:27:11

只需调用GetEnvironmentVariable()。它适用于 Windows 维护的进程状态,而不是 putenv() 修改的 CRT 状态。

Just call GetEnvironmentVariable(). It works on the process state as maintained by Windows, not the CRT state modified by putenv().

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