gpt4 book ai didi

c++ - 无法通过 CreateProcess API 打开 chrome 浏览器

转载 作者:行者123 更新时间:2023-11-30 05:39:33 25 4
gpt4 key购买 nike

我正在尝试通过 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;
}

最佳答案

尝试从命令行中删除不需要的引号

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

关于c++ - 无法通过 CreateProcess API 打开 chrome 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32308508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com