ShellExecute fails for local html or file URLs

前端 未结 4 519
一整个雨季
一整个雨季 2020-12-19 11:48

Our company is migrating our help systems over to HTML5 format under Flare. We\'ve also added Topic based access to the help systems using Flare CSHID\'s on the URI command

4条回答
  •  执笔经年
    2020-12-19 12:06

    After some back-and-forth with Microsoft's MSDN team, they reviewed the source code to the ShellExecute() call and it was determined that yes, when processing File:/// based URLs in ShellExecute(), the ShellExecute() call will strip off the # and any data it finds after the # before launching the default browser and sending in the HTML page to open. MS's stance is that they do this deliberately to prevent injections into the function.

    The solution was to beef up the ShellExecute() call by searching the URL for a # and if one was found, then we would manually launch the default browser with the URL. Here's the pseudocode

    void WebDrive_ShellExecute(LPCTSTR szURL)
    {
        if ( _tcschr(szURL,_T('#')) )
        {
            //
            //Get Default Browser from Registry, then launch it.
            //
            ::RegGetStr(HKCR,_T("HTTP\\Shell\\Open\\Command"),szBrowser);
            ::CreateProcess ( NULL, szBrowser + _T(" ") + szURL, NULL, NULL, FALSE, 0, NULL, NULL, &sui, &pi);
        }
        else
            ShellExecute(NULL,_T("open"),szURL,NULL,NULL,SW_SHOWNORMAL);
    }
    

    Granted there's a bit more to the c++ code, but this general design worked for us.

提交回复
热议问题