windows - How to print lpEnvironment got from CreateEnvironmentBlock() -
see createenvironmentblock written in c++.
bool winapi createenvironmentblock( _out_ lpvoid *lpenvironment, _in_opt_ handle htoken, _in_ bool binherit ); lpenvironment [out] type: lpvoid* when last function returns, receives pointer new environment block. environment block array of null-terminated unicode strings. list ends 2 nulls (\0\0).
i able call createenvironmentblock() successfully, need know how print content of lpenvironment (i mean want print environment variables).
it list of strings, terminated empty string. sample code created win32 console application project template in vs:
#include "stdafx.h" #include <windows.h> #include <userenv.h> #include <assert.h> #pragma comment(lib, "userenv.lib") int main() { handle htoken = null; bool ok = openprocesstoken(getcurrentprocess(), token_read, &htoken); assert(ok); wchar_t* penv = l""; ok = createenvironmentblock((void**)&penv, htoken, true); assert(ok); while (*penv) { printf("%ls\n", penv); penv += wcslen(penv) + 1; } return 0; }
Comments
Post a Comment