Article View: borland.public.cppbuilder.nativeapi
Article #573ShellExecute does not work - open HTML file with spaces in the file path.
From: const * const char ME
Date: Thu, 28 Feb 2008 16:21
Date: Thu, 28 Feb 2008 16:21
41 lines
2514 bytes
2514 bytes
I have code like this:
ShellExecute(NULL, "open", aPath, NULL, NULL, SW_SHOWMAXIMIZED);
where aPath = "D:\Example Projects\test.html "
Note the space in the path above. When executed in Vista (default browser =
IE7) IE automatically changes this to:
"D:\Example%20Projects\test.html " and produces a "Navigation to the webpage
was cancelled" error for some reason.
Interestingly to me, on XP, (also with IE7) it does NOT have this problem. I
suspect it has something to do with a local file based URL and protected
mode in IE?
Anyway - So I tried this (figuring it would remove the spaces):
char shortPath[MAX_PATH] = {'\0'};
GetShortPathName(aPath.c_str(), shortPath, MAX_PATH);
ShellExecute(NULL, "open", shortPath, NULL, NULL, SW_SHOWMAXIMIZED);
However before displaying it, IE expands the short path to the full path,
then does the exact same thing - replacing the space with %20 - which again
fails in the same way. Again - only on Vista!
Lastly - I noticed something very odd... The problem seems to be related to
if the browser is already running!
To reproduce:
1. Close all the IE windows
2. Execute the above code. It works as it should - with no %20's - they
are left alone as spaces.
3. Without closing IE, immediately execute the same code again, it has %20
characters parsed into the address and fails!
Thus - if you have an IE window opened before executing the above code with
a path that has spaces then it fails - otherwise it works....
Any ideas???
TIA
Technical Details
Message-ID:
<47c6dfd8$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2980291559cdba2a,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "const * const char ME" <smakjasdhfg@iuyd.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: ShellExecute does not work - open HTML file with spaces in the file path. Date: Thu, 28 Feb 2008 08:21:58 -0800 Lines: 45 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 209.17.173.11 Message-ID: <47c6dfd8$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1204215768 209.17.173.11 (28 Feb 2008 08:22:48 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail