在 Windows 上通过 CreateProcessW() 启动新进程的 UNICODE 环境块是什么样子的?

发布于 2024-10-02 03:55:54 字数 842 浏览 3 评论 0原文

本质上,我想创建一个新进程并从父进程为其定义环境。我想使用 CreateProcessW 并将(修改后的)UNICODE 环境传递到 lpEnvironment 中,但我不确定与 ANSII 环境块相比内容应该是什么样子。

我真正找到的唯一文档是在 MSDN 上:

请注意,ANSI 环境块是 以两个零字节终止:一个用于 最后一个字符串,还有一个要终止 块。 Unicode 环境块 以四个零字节终止:两个 对于最后一个字符串,还有两个 终止块。

现在我尝试

  1. 调用 GetEnvironmentStrings 并将其传递给子进程
  2. 调用 GetEnvironmentStringsW 并将其传递给子进程
  3. 使用我的附加环境字符串修改这些块并将其传递给

非其中的工作

我真的只能将 lpEnvironment 设置为 NULL 才能使其工作,但现在我必须更改 &恢复我父母的处理环境 - 这是要走的路吗?

(我也设置了CREATE_UNICODE_ENVIRONMENT

谁能告诉我UNICODE环境块有什么特别之处 - 当我只使用ASCII 填充并调用 CreateProcessA()...

Essentially, I would like to create a new process and define the environment for it from the parent 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

  1. call GetEnvironmentStrings and pass it on to the child process
  2. call GetEnvironmentStringsW and pass it to the child process
  3. 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()...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妖妓 2024-10-09 03:55:54

如果没有代码,我不知道你做错了什么。但这是有效的:

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());
}

也许这会让你知道自己做错了什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文