msdn中CreateProcess函数关于lpApplicationName参数的说明里面有这么一段话
The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. If the file name does not contain an extension, .exe is assumed. Therefore, if the file name extension is .com, this parameter must include the .com extension. [1]
但是实际测试表明并不会有默认的.exe的扩展名的
[1]ms-help://MS.MSDNQTR.v90.en/dllproc/base/createprocess.htm
[2]测试环境:windows xp sp2 + vs2008 sp1
The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. If the file name does not contain an extension, .exe is assumed. Therefore, if the file name extension is .com, this parameter must include the .com extension. [1]
但是实际测试表明并不会有默认的.exe的扩展名的
#include <windows.h>
int main()
{
STARTUPINFO si = { 0 };
si.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi = { 0 };
CreateProcess(L"D:\\a.exe",NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); // 成功
//CreateProcess(L"D:\\a",NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); // 不成功
CloseHandle(pi.hProcess);
return 0;
}[1]ms-help://MS.MSDNQTR.v90.en/dllproc/base/createprocess.htm
[2]测试环境:windows xp sp2 + vs2008 sp1
本文通过测试验证了Windows系统下CreateProcess函数对于lpApplicationName参数的处理方式,并非如MSDN文档所述会默认添加.exe扩展名。文章提供了一个示例代码,展示了指定完整路径时函数能够正确执行,而省略.exe时则无法成功。
2万+

被折叠的 条评论
为什么被折叠?



