CreateProcess()无法正确启动进程

时间:2013-04-26 02:10:08

标签: c++ winapi

我试图使用下面的函数简单地启动一个应用程序,但它似乎正常工作。它不会从桌面启动我的测试应用程序,但当我将其移动到下载中的子文件夹时,它工作正常。我从配置文件中提取目录信息,并考虑到我已经可以从一个单独的文件夹启动测试应用程序,我怀疑它与我的目录信息有什么关系。

bool StartTest(){
    char WOW_PATH[MAX_PATH];
    char WOW_PATH_FULL[MAX_PATH];
    STARTUPINFO SUI;
    PROCESS_INFORMATION PROCINFO;

    SUI.cb          = sizeof(STARTUPINFO);
    SUI.lpReserved  = 0;
    SUI.lpTitle     = 0;
    SUI.dwFlags     = STARTF_RUNFULLSCREEN;
    SUI.wShowWindow = SW_SHOW;
    SUI.cbReserved2 = 0;
    SUI.lpReserved2 = 0;

    ZeroMemory(&PROCINFO,sizeof(PROCINFO));

    ifstream File;
    File.open("config.txt");
    File.getline(WOW_PATH,MAX_PATH);
    File.close();

    strcpy(WOW_PATH_FULL,WOW_PATH);

    strcpy(WOW_PATH_FULL,"\Test.exe");

    if(!CreateProcess(WOW_PATH_FULL,0,0,0,false,0,0,WOW_PATH,&SUI,&PROCINFO))
        return 0;

    CloseHandle(PROCINFO.hProcess);
    CloseHandle(PROCINFO.hThread);

    return 1;
}

1 个答案:

答案 0 :(得分:3)

我怀疑以下行需要反斜杠转义。第二个电话需要是strcat,而不是strcpy。

strcpy(WOW_PATH_FULL,WOW_PATH);
strcpy(WOW_PATH_FULL,"\Test.exe");

以下是修复:

strcpy(WOW_PATH_FULL,WOW_PATH);
strcat(WOW_PATH_FULL,"\\Test.exe");