简体   繁体   中英

Unexpected behavior while opening escaped file:/// URL in IE

I could swear to god that the code below used to work a week ago. I can tell that because the software I develop depends on it.

This code chunk is supposed to open an html page from a local HDD using IE:

(These strings are not hardcoded in my actual example. What it does is this -- it escapes the path to the local html file and adds file:/// in front.)

LPCTSTR m_strBrowser = L"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe";
LPCTSTR addr2 = L"\"file:///C%3a%5cUsers%5cUserName%5cAppData%5cLocal%5cTemp%5cReport_View.htm\"";

ShellExecute(hMain, NULL, m_strBrowser, addr2, NULL, SW_SHOWNORMAL);

But what I get when I test it today is just the home page in IE.

Any idea what is wrong here?

PS. The Report_View.htm file exists in the file system. PS2. If I copy and paste the escaped URL into Chrome or FF, it opens just fine.

Well, evidently they made some changes to the IE and now the file protocol URL can no longer contain arbitrary escaping. From my experience, the only way to make it work with IE is by getting the file protocol path by calling the UrlCreateFromPath API:

//You get this path from Registry
LPCTSTR m_strBrowser = L"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe";

LPCTSTR addr2 = L"C:\\Users\\UserName\\AppData\\Local\\Temp\\Report_View.htm";

DWORD dwSz_buff_addr2 = INTERNET_MAX_URL_LENGTH;
TCHAR buff_addr2[INTERNET_MAX_URL_LENGTH];
if(SUCCEEDED(UrlCreateFromPath(addr2, buff_addr2, &dwSz_buff_addr2, NULL))
{
    ShellExecute(hMain, NULL, m_strBrowser, buff_addr2, NULL, SW_SHOWNORMAL);
}

Also I'm not sure the parameter should be quoted in itself (it doesn't have space characters anyway), also not sure about the escaping.

Try:

LPCTSTR addr2 = L"file:///C|/Users/UserName/AppData/Local/Temp/Report_View.htm";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM