我想创建一个文件名不具有.exe
扩展名的进程。这与Open an executable file without an “.exe” extension with ShellExecute的问题相同,只有CreateProcess
。他的问题的答案是设置sei.lpClass = TEXT("exefile");
。 STARTUPINFO
结构中没有此类参数。
是否有CreateProcess
的等效解决方案。目前,它失败,没有扩展。甚至没有给出正确的错误信息。只是崩溃了程序。
对不起,这是一个完整的测试程序,展示了我的问题:
#include "stdafx.h"
#include <Windows.h>
LPCTSTR FILE_PATH_NAME = _tcsdup( TEXT( "C:\\File1.exe" ) ); // ok, launches new process correctly
//LPCTSTR FILE_PATH_NAME = _tcsdup( TEXT( "C:\\File1" ) ); // debug assertion in mfc
LPCTSTR FILE_PATH_NAME = _tcsdup( TEXT( "C:\\File1." ) ); // ok, launches new process correctly. Needs ending period (.) to work
LPTSTR commandLine = _tcsdup( TEXT( "1234" ) );
int main()
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory( &pi, sizeof( pi ) );
ZeroMemory( &si, sizeof( si ) );
si.cb = sizeof( si );
CreateProcess
(
FILE_PATH_NAME, // must be fully qualified file path name
commandLine, // Command line (cannot be const or literal str)
NULL, // Process handle is not inheritable
NULL, // Thread handle is not inheritable
FALSE, // handle inheritance false
0, // default
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to startupinfo structure
&pi // Pointer to process_information structure
);
DWORD lastError = GetLastError();
if( lastError != ERROR_SUCCESS )
{
// failed
}
CloseHandle( pi.hThread );
CloseHandle( pi.hProcess );
return 0;
}
崩溃图片