How does a UNICODE environment block look like to start a new process via CreateProcessW() on Windows?
Essentially, I would like to create a new process and define the environment for it from the parent开发者_Go百科 process. I would like to use CreateProcessW and pass a (modified) UNICODE environment into lpEnvironment, but I'm not sure what the content should look like compared to an ANSII environment block.
The only documentation I really found is on MSDN:
Note that an ANSI environment block is terminated by two zero bytes: one for the last string, one more to terminate the block. A Unicode environment block is terminated by four zero bytes: two for the last string, two more to terminate the block.
Now I tried to
- call
GetEnvironmentStringsand pass it on to the child process - call
GetEnvironmentStringsWand pass it to the child process - modify these blocks with my additional environment strings and pass it on
non of them work
I really only could set lpEnvironment to NULL to get it to work, but now I would have to change & revert my parents processing environment - is that the way to go here?
(I also did set CREATE_UNICODE_ENVIRONMENT)
Could anyone please tell me what is so special about UNICODE environment blocks - it did work, when I just use ASCII stuff and call CreateProcessA()...
I have no idea what you are doing wrong without code. But this works:
STARTUPINFO startInfo = {0};
PROCESS_INFORMATION procInfo = {0};
WCHAR env[] = L"key=value\0key2=value2\0\0";
WCHAR cmdline[] = L"calc";
startInfo.cb = sizeof(startInfo);
if(!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT, env, NULL, &startInfo, &procInfo))
{
printf("Error %d\n", GetLastError());
}
Perhaps that will give you an idea of what you are doing wrong.
加载中,请稍侯......
精彩评论