0

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?

4

1 回答 1

0

只要打电话GetEnvironmentVariable()。它适用于由 Windows 维护的进程状态,而不是由putenv().

于 2011-12-30T09:54:11.650 回答