Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages
Started by const * const char ME
Thu, 28 Feb 2008 16:21
ShellExecute does not work - open HTML file with spaces in the file path.
Author: 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
Re: ShellExecute does not work - open HTML file with spaces in the file path.
Author: Ed Mulroy [TeamB]
Date: Thu, 28 Feb 2008 17:16
Date: Thu, 28 Feb 2008 17:16
57 lines
3208 bytes
3208 bytes
The trailing space in the file name cannot be good. At best it will be
ignored. Get rid of it.
This is just a guess but I suspect that if IE is already running that the
command line is passed on to the in-memory module while if it is not already
running then the command line is passed to the command interpreter. The
command interpreter requires paths and/or file names containing spaces to be
encased in quotes.
Try changing
aPath = "D:\Example Projects\test.html ";
to
aPath = "\"D:\Example Projects\test.html\"";
. Ed
> const * const char ME wrote in message
> news:47c6dfd8$1@newsgroups.borland.com...
>
>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....
Re: ShellExecute does not work - open HTML file with spaces in the file path.
Author: D Ray
Date: Fri, 29 Feb 2008 04:33
Date: Fri, 29 Feb 2008 04:33
1 lines
997 bytes
997 bytes
Is D: a network or a local drive?
Re: ShellExecute does not work - open HTML file with spaces in the file path.
Author: const * const char ME
Date: Mon, 03 Mar 2008 16:02
Date: Mon, 03 Mar 2008 16:02
6 lines
1185 bytes
1185 bytes
"D Ray" <david@timecalc.com> wrote in message news:47c78ab1$1@newsgroups.borland.com... > Is D: a network or a local drive? No.
Re: ShellExecute does not work - open HTML file with spaces in the file path.
Author: Regis St-Gelais
Date: Mon, 03 Mar 2008 18:59
Date: Mon, 03 Mar 2008 18:59
7 lines
1406 bytes
1406 bytes
> "D Ray" <david@timecalc.com> wrote in message > news:47c78ab1$1@newsgroups.borland.com... >> Is D: a network or a local drive? > > No. It is not a Yes/No question !!!
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads