为了加强自己的记忆,我决定用文字记录下来。
这是源代码,主要是输出环境变量,具体可以参考CreateEnvironmentBlock函数
1 #include <Windows.h> 2 #include <UserEnv.h> 3 #include <assert.h> 4 #include <stdio.h> 5 #pragma comment(lib, "userenv.lib") 6 #pragma warning(disable : 4996) 7 8 int main() 9 { 10 HANDLE hToken = NULL; 11 BOOL ok = OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken); 12 /*assert(ok); 13 14 wchar_t* penv = NULL; 15 ok = CreateEnvironmentBlock((void**)&penv, hToken, TRUE); 16 assert(ok); 17 18 while (*penv) { 19 printf("%lsn", penv); 20 penv += wcslen(penv) + 1; 21 }*/ 22 wchar_t* wnext = NULL; 23 LPVOID pEnvironment = NULL; 24 ok = CreateEnvironmentBlock(&pEnvironment, 25 hToken, 26 FALSE); 27 if (!ok) 28 { 29 // handle error 30 } 31 32 wchar_t* wtemp = (wchar_t*)pEnvironment; 33 34 do 35 { 36 wnext = wtemp + wcslen(wtemp) + 1; 37 int m = wcslen(wtemp); 38 if (*(wnext+1) == L'