调用 CreateProcessAsUser 时,我是否需要在 lpCommandLine 中指定一个 exe 路径作为
Do I need to specify an exe path as the 1st parameter in lpCommandLine when calling CreateProcessAsUser?
我似乎找不到明确的答案。我的目标是使用用户令牌启动一个进程。假设,有问题的过程是这样开始的:
"C:My folderMy proc.exe" param=1
因此,当我为创建进程作为用户 API 指定lpCommandLine
参数时,我是否需要将可执行路径指定为第一个参数:
LPCTSTR pStrExePath = L"C:\My folder\My proc.exe";
TCHAR buffCmdLine[MAX_PATH];
if(SUCCEEDED(::StringCchPrintf(buffCmdLine, MAX_PATH,
L""%s" %s", pStrExePath, L"param=1")))
bResult = CreateProcessAsUser(
hToken, // client's access token
pStrExePath, // file to execute
buffCmdLine, // command line
NULL, // pointer to process SECURITY_ATTRIBUTES
NULL, // pointer to thread SECURITY_ATTRIBUTES
FALSE, // handles are not inheritable
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, // creation flags
envBlock, // pointer to new environment block
NULL, // name of current directory
&si, // pointer to STARTUPINFO structure
&pi // receives information about new process
);
或者我可以省略 exe 路径并执行此操作吗?
LPCTSTR pStrExePath = L"C:\My folder\My proc.exe";
TCHAR buffCmdLine[MAX_PATH];
if(SUCCEEDED(::StringCchCopy(buffCmdLine, MAX_PATH, L"param=1")))
bResult = CreateProcessAsUser(
hToken, // client's access token
pStrExePath, // file to execute
buffCmdLine, // command line
NULL, // pointer to process SECURITY_ATTRIBUTES
NULL, // pointer to thread SECURITY_ATTRIBUTES
FALSE, // handles are not inheritable
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, // creation flags
envBlock, // pointer to new environment block
NULL, // name of current directory
&si, // pointer to STARTUPINFO structure
&pi // receives information about new process
);
它们似乎都有效。
阅读文档,这两种情况都应该有效。
来自 MSDN
如果 lpApplicationName 和 lpCommandLine 都是非空的, *lpApplicationName 指定要执行的模块,*lpCommandLine 指定命令行。新进程可以使用 GetCommandLine 来 检索整个命令行。用 C 语言编写的控制台进程可以 使用 argc 和 argv 参数解析命令行。因为 argv[0] 是模块名称,C 程序员一般重复模块 名称作为命令行中的第一个标记。
我同意文档可能更清楚,说它接受命令行的参数部分或lpCommandLine
中的完整命令行,当lpApplicationName
为非 NULL 时。
更新:在 lpApplicationName 为 NULL 的情况下,文档更好
如果 lpApplicationName 为 NULL,则命令行的第一个空格分隔标记指定模块名称...
更新 2 :有一个关于这些参数的很好的文档 了解创建进程 和 命令行参数.阅读本文档,我了解到您的两种情况之间存在差异。当您在lpCommandLine
中提供lpApplicationName
和参数时,子进程将按lpCommandLine
中的原样解析命令行。因此,如果您不复制 exe 路径,argv[0] 将不会像往常一样表示 exe 路径,而是 param=1。
- 检查路径是否包含C++中的另一个路径
- 如何使用条件计算 3D 网格中从一个点到另一个点的所有路径
- 在由邻接列表表示的树中查找节点到另一个给定节点之间的路径
- 从另一个应用启动我的应用时出现相对路径更改问题
- 如何在另一个系统上启用文件路径
- 添加一个节点,并在通用树中的两个给定节点之间找到路径成本,其中c 中的儿童列表
- 如果路径的每个元素不存在,请为其创建一个目录
- “并非所有控制路径都返回一个值./&quot“控制可能达到非空隙功能的末端”.验证时循环时
- 我正在尝试在Eclipse中构建一个C 项目,但是即使在使用MINGW路径设置路径变量之后,也会获得构建错误
- 最短路径问题与一个变化
- 在树中查找一个路径/子路径,使权重之和小于给定的整数
- 使用 ros launch 创建一个目录,然后将其路径传递给不同的节点
- 如何确保迷宫总是有一个有效的路径C++
- 有没有一个带有距离标记的最短路径算法的开源实现
- 在MacOS上编译一个动态库,库搜索路径指向同一目录(CMake)
- 在一个有权无向图中寻找某一长度的所有路径
- 类型名称路径由一个静态变量隐藏
- Qt:如何创建一个文件(其路径需要目录)
- 给定一个二叉搜索树和一个数字,找到一个路径,其节点的数据被添加为给定的数字。
- 将filesystem::path元素附加到另一个路径的最佳方法是什么?