C++API打开其他进程

来源:百度知道 编辑:UC知道 时间:2024/05/27 13:17:53
#include<windows.h>
main()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
CreateProcess(NULL,"e:\\GAME\\红警\\ra2.exe",NULL,NULL,0,0,NULL,NULL,&si,&pi);
}运行没反应,ra2.exe并没有打开嘛

用这个
ShellExecute(NULL, "open", "e:\\GAME\\红警\\ra2.exe", "", "", SW_SHOWMAXIMIZED);

CreateProcess需要初始化2个结构体的。。

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

CreateProcess()的第一个参数为进程的名称(或者全路径+名称),第二个参数是执行该进程的时候要传递的命令行参数。你把红警的路径放在第一个参数位置试试。

ShellExecute
Version 5.0. The shellexecute command specifies an application or data file that AutoRun uses to call ShellExecuteEx.

shellexecute=[filepath\]filename[param1, [param2]...]

Parameters
filepath
A string that contains the fully-qualified path of the directory that contains the data or executable file. If no path is specified, the file must be in the drive's root directory.
filename
A string that contains the file's name. If it is an executable file, it is launched. If it is a data file, it must be a member of a file class. ShellEx