Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CreateProcess启动边缘浏览器_C++_Windows_Powershell - Fatal编程技术网

C++ CreateProcess启动边缘浏览器

C++ CreateProcess启动边缘浏览器,c++,windows,powershell,C++,Windows,Powershell,我有一个powershell脚本,可以在edge浏览器上启动网页。当您从命令行运行此脚本时,它工作正常 启动WebPageFromEdge.ps1 start microsoft-edge:https://www.youtube.com $url = 'https://www.youtube.com/' $IE = new-object -com internetexplorer.application $IE.navigate2($url) $IE.visible = $true 启动We

我有一个powershell脚本,可以在edge浏览器上启动网页。当您从命令行运行此脚本时,它工作正常

启动WebPageFromEdge.ps1

start microsoft-edge:https://www.youtube.com
$url = 'https://www.youtube.com/'
$IE = new-object -com internetexplorer.application
$IE.navigate2($url)
$IE.visible = $true
启动WebPageFromie.ps1

start microsoft-edge:https://www.youtube.com
$url = 'https://www.youtube.com/'
$IE = new-object -com internetexplorer.application
$IE.navigate2($url)
$IE.visible = $true
我的任务是从Windows C++控制台应用程序中启动这个任务。我有下面同样的代码。使用CreateProcess API调用时,脚本未启动浏览器。我有另一个powershell脚本在IE中启动网页。它工作正常

int main()
{
    std::string cmdExc = "powershell.exe -ExecutionPolicy Bypass -file \"C:\\launchWebPageFromEdge.ps1\"";
    STARTUPINFO startInfo;
    PROCESS_INFORMATION procInfo;
    
    if (!CreateProcess(NULL,
            const_cast<char *>(cmdExc.c_str()), // Command line
            NULL,           // Process handle not inheritable
            NULL,           // Thread handle not inheritable
            TRUE,           // Set handle inheritance to TRUE
            REALTIME_PRIORITY_CLASS | CREATE_NO_WINDOW,  // creation flags
            NULL,           // Use parent's environment block
            NULL,           // Use parent's starting directory 
            &startInfo,     // Pointer to STARTUPINFO structure
            &procInfo)      // Pointer to PROCESS_INFORMATION structure
            )
    {
        std::cout << "error\n";
        return -1;
    }

    WaitForSingleObject(procInfo.hProcess, INFINITE);
    return 0;
}
intmain()
{
std::string cmdExc=“powershell.exe-ExecutionPolicy旁路-file\”C:\\launchWebPageFromEdge.ps1\”;
STARTUPINFO startInfo;
处理信息procInfo;
如果(!CreateProcess)为空,
const_cast(cmdExc.c_str()),//命令行
NULL,//进程句柄不可继承
NULL,//线程句柄不可继承
TRUE,//将句柄继承设置为TRUE
实时_优先级|创建_否_窗口,//创建标志
NULL,//使用父级的环境块
NULL,//使用父级的起始目录
&startInfo,//指向STARTUPINFO结构的指针
&procInfo)//指向进程信息结构的指针
)
{
std::cout该结构未初始化。它不是一个输出结构,因此在那里传递垃圾可能会导致
CreateProcess
失败。您可以像这样轻松修复它:

STARTUPINFO startInfo { sizeof(STARTUPINFO) };
请注意,应关闭中返回的
hProcess
hThread
句柄


但是您根本不需要PowerShell来打开Edge

通过以下方法可以轻松实现这一点:


实时\u优先级\u类?真的吗?另一方面,您正在泄漏
CreateProcess()
句柄的输出。此外,您是否尝试使用
ShellExecute/Ex()
启动
microsoft edge:https://www.youtube.com
直接使用而不使用脚本?