是否有API可以获取操作系统中定义的原始变量值
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需调用
GetEnvironmentVariable()
。它适用于 Windows 维护的进程状态,而不是putenv()
修改的 CRT 状态。Just call
GetEnvironmentVariable()
. It works on the process state as maintained by Windows, not the CRT state modified byputenv()
.