使用 C++ 使用命令行参数调用 CreateProcessAsUser 的说明 [英] Clarification on calling CreateProcessAsUser with command line parameters using C++

查看:206
本文介绍了使用 C++ 使用命令行参数调用 CreateProcessAsUser 的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对调用 CreateProcessAsUser 带有命令行参数.因此,无需详细填写其余参数,有人可以确认这是应该如何完成的吗?(换句话说,我应该把exe文件路径作为第一个命令行参数,还是指定为lpApplicationName就足够了?)

I'm somewhat confused about the proper way of calling CreateProcessAsUser with command line parameters. So without going into details of filling out the rest of its parameters, can someone confirm that this is how it should be done? (In other words, should I put the exe file path as the first command line parameter, or specifying it as lpApplicationName is enough?)

LPCTSTR pExePath = L"c:\\program files\\sub dir\\program.exe";
LPCTSTR pCmdLine = L"v=\"one two\"";

TCHAR buff[MAX_PATH];
StringCchCopy(buff, MAX_PATH, _T("\""));
StringCbCat(buff, MAX_PATH, pExePath);
StringCbCat(buff, MAX_PATH, _T("\" "));
StringCbCat(buff, MAX_PATH, pCmdLine);

CreateProcessAsUser(hToken, pExePath, buff, NULL, NULL, FALSE, dwFlags, NULL, NULL, &si, &pi);

推荐答案

如果 CreateProcessAsUser 的 2nd param 是 NULL,那么模块名称必须是第一个空格–第三个参数中的分隔标记.

If 2nd param to CreateProcessAsUser is NULL, then the module name must be the first white space–delimited token in the 3rd param.

如果 CreateProcessAsUser 的第二个参数不是 NULL,那么它将被当作可执行文件来执行.在这种情况下,第三个参数可以是

If 2nd param to CreateProcessAsUser is not NULL, then it will be taken as the executable to execute. In this case, the 3rd param can either be

a) "EXENAME p1 p2"

也可以

b) "p1 p2"

如果选择了a),那么子进程就会有以下内容

If you chose a), then the child process will have the following

argv[0] -->EXENAME

argv[1] -->p1

argv[2] -->p2

如果你选择了b),那么子进程就会有

If you chose b), then the child process will have

argv[0] -->p1

argv[1] -->p2

无论哪种方式,要执行的进程都是 EXENAME(CreateProcessAsUser 的第二个参数).然而,被调用的进程应该知道命令行参数的传入方式.

Either way, the process to be executed would be EXENAME (the 2nd param to CreateProcessAsUser). The called process however should be aware of the way command line arguments are going to be coming in.

如果您使用 b),您还可以选择将第二个参数作为 NULL 传递给 CreateProcessAsUser.

If you use b), you also have the option of passing 2nd param to CreateProcessAsUser as NULL.

这篇关于使用 C++ 使用命令行参数调用 CreateProcessAsUser 的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆