2015-08-31 144 views
1

我想通過CreateProcess API打開Chrome瀏覽器。我無法這樣做。未能通過CreateProcess API打開Chrome瀏覽器

我試着這樣做:

string commandLine = "\"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\""; 
    commandLine += " -- "; 
    commandLine += pURLinfo->szURL; 
    CreateProcess(commandLine.c_str(), NULL, NULL, NULL, FALSE, 
       CREATE_NEW_CONSOLE, NULL, NULL, &startupInfo, &processInformation); 

的CreateProcess返回錯誤123 也許有另一種方式來打開它。 (我不是在談論ShellExecute)。

更新:我的代碼現在看起來像這樣,但我仍然無法運行chrome。

STARTUPINFOA si; 
    PROCESS_INFORMATION pi; 

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

// Start the child process. 
if (!CreateProcessA("C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe",  // No module name (use command line) 
    NULL, 
    NULL,   // Process handle not inheritable 
    NULL,   // Thread handle not inhberitable 
    FALSE,   // Set handle inheritance to FALSE 
    0,    // No creation flags 
    NULL,   // Use parent's environment block 
    NULL,   // Use parent's starting directory 
    &si,   // Pointer to STARTUPINFO structure 
    &pi)   // Pointer to PROCESS_INFORMATION structure 
    ) 
{ 
    printf("CreateProcess failed (%d).\n", GetLastError()); 
    getchar(); 
    return 0; 
} 
+0

在這裏你去https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs刪除不需要的報價。 85).aspx aaa,它是ERROR_INVALID_NAME。我相信你知道該怎麼做。 – Pyjong

+1

錯誤123是ERROR_INVALID_NAME(「文件名,目錄名稱或卷標語法不正確。」)。確保你會提供正確的路徑。 –

+0

順便說一句,可以是dup http://stackoverflow.com/questions/15469666/invoking-nvcc-exe-using-createprocess –

回答

1

嘗試從命令行

string commandLine = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"; 
相關問題