Discussion:
Opening URL with ShellExecute returns SE_ERR_ACCESSDENIED on Windows XP
(too old to reply)
Gingko
2010-01-23 12:32:39 UTC
Permalink
Hello,

I have an application that uses (several times) the function "ShellExecute"
for opening a URL inside a web browser (using the default web browser), with
a call like the following one :

int nResult = (int)ShellExecute(hMainWnd, "open",
"http://fr.wikipedia.org/", NULL, NULL, SW_SHOWNORMAL);

(given URL is a generic sample, of course, actual values are different and
there are 3 different ones)

This used to work on Windows XP, and this still works on Windows Vista and
Windows 7.

But now, for an unknown time, maybe after some update to Windows XP, the
call no longer opens anything and returns error code 5 (=
SE_ERR_ACCESSDENIED).

Same result whatever I compile in Unicode or not.

Used default brower is Mozilla Firefox.
OS is Windows XP Professional SP3, French edition, all critical and many not
critical updates installed as of today (on all computers).

I checked this using 3 different computers having Windows XP (for getting an
error result) and also 3 different computers having Windows Vista or Windows
7 (actually multiboot of the same computers), where it works correctly.

I would like to know how to have it working again on Windows XP, or if there
is some other method for opening an URL using the default browser that would
be garanteed to work on Windows XP.

I made some searches using Google with the words ShellExecute and
SE_ERR_ACCESSDENIED, this gives a lot of results, but I didn't find any that
really apply to my case, or that give a solution working for me.

Can somebody help me ?
Thanks for any help.

Gilles

P.S.: I already asked this question in microsoft.public.platformsdk.shell,
but it looks like this newsgroup is no longer managed.
Alexander Grigoriev
2010-01-23 17:15:04 UTC
Permalink
If you just type the same exact URL to Start->Run dialog, does it work? I
suppose it goes through the same ShellExecute.

Also try ShellExecuteEx.

I wonder also if the verb 'open' got somehow localised in XP SP3 ('ferme'?).

Check if it works with IE as a default browser.
Post by Gingko
Hello,
I have an application that uses (several times) the function
"ShellExecute"
for opening a URL inside a web browser (using the default web browser), with
int nResult = (int)ShellExecute(hMainWnd, "open",
"http://fr.wikipedia.org/", NULL, NULL, SW_SHOWNORMAL);
(given URL is a generic sample, of course, actual values are different and
there are 3 different ones)
This used to work on Windows XP, and this still works on Windows Vista and
Windows 7.
But now, for an unknown time, maybe after some update to Windows XP, the
call no longer opens anything and returns error code 5 (=
SE_ERR_ACCESSDENIED).
Same result whatever I compile in Unicode or not.
Used default brower is Mozilla Firefox.
OS is Windows XP Professional SP3, French edition, all critical and many not
critical updates installed as of today (on all computers).
I checked this using 3 different computers having Windows XP (for getting an
error result) and also 3 different computers having Windows Vista or Windows
7 (actually multiboot of the same computers), where it works correctly.
I would like to know how to have it working again on Windows XP, or if there
is some other method for opening an URL using the default browser that would
be garanteed to work on Windows XP.
I made some searches using Google with the words ShellExecute and
SE_ERR_ACCESSDENIED, this gives a lot of results, but I didn't find any that
really apply to my case, or that give a solution working for me.
Can somebody help me ?
Thanks for any help.
Gilles
P.S.: I already asked this question in microsoft.public.platformsdk.shell,
but it looks like this newsgroup is no longer managed.
Gingko
2010-01-23 23:53:15 UTC
Permalink
----- Original Message -----
From: "Alexander Grigoriev" <***@earthlink.net>
Newsgroups: microsoft.public.win32.programmer.ui
Sent: Saturday, January 23, 2010 6:15 PM
Subject: Re: Opening URL with ShellExecute returns SE_ERR_ACCESSDENIED on
Windows XP

Thank you for your answer.
Post by Alexander Grigoriev
If you just type the same exact URL to Start->Run dialog, does it work? I
suppose it goes through the same ShellExecute.
Yes it works.
I can also create a URL shortcut on the desktop with the same URL and it
works prefectly.
Post by Alexander Grigoriev
Also try ShellExecuteEx.
I just tried.

Same result about the SE_ERR_ACCESSDENIED error code (returned in the
"hInstApp" field).

But with ShellExecuteEx, in addition I get an error message box displaying
two lines :
(1) a copy of the URL used,
(2) The string "La clé de recherche requise n'a été trouvée dans aucun
contexte d'activation actif"

A search on Internet shows that this message seems to correspond to the
(apparently quite common) following English error message :
"The requested look up key was not found in any activation context"

This message seems to have been very common at the release time of Internet
Explorer 7, and the given "solutions" were (1) Reboot the computer after IE7
installation, or (2) Uninstall IE7, revert to IE6, and then reinstall IE7
using Windows Update, or (3) switch to Mozilla Firefox.

But :
(1) My computer (actually all of my three computers running XP have this
problem) have been rebooted at least once every day since the release of
IE7, something like two years ago.
(2) I'm currently having IE8 on my computers, I'm not sure how I can
consider reverting to IE6 and then reinstall IE8 with IE7 eventually
intervening in the middle.
(3) I already use Mozilla Firefox for a time even largely longer than the
release of IE7.

Also, this seems to be a common error on Windows XP, I cannot ask all users
of my application to do repairs like that for the only purpose of having
commands needing ShellExecute working.
Post by Alexander Grigoriev
I wonder also if the verb 'open' got somehow localised in XP SP3 ('ferme'?).
French translation would be "ouvrir", but anyway this string is not
localizable, and also my application perfectly works with the exact same
command on Windows Vista or Windows 7, French Editions.
Post by Alexander Grigoriev
Check if it works with IE as a default browser.
No, it doesn't work better that way.

Gilles
Alexander Grigoriev
2010-01-24 02:58:23 UTC
Permalink
It must be STATUS_SXS_KEY_NOT_FOUND. Its meaning, in the usual Microsoft
tradition, is not explained anywhere.

Do you by any chance have CoInitializeEx(NULL, COINIT_MULTITHREADED) in your
program?
Post by Gingko
----- Original Message -----
Newsgroups: microsoft.public.win32.programmer.ui
Sent: Saturday, January 23, 2010 6:15 PM
Subject: Re: Opening URL with ShellExecute returns SE_ERR_ACCESSDENIED on
Windows XP
Thank you for your answer.
Post by Alexander Grigoriev
If you just type the same exact URL to Start->Run dialog, does it work? I
suppose it goes through the same ShellExecute.
Yes it works.
I can also create a URL shortcut on the desktop with the same URL and it
works prefectly.
Post by Alexander Grigoriev
Also try ShellExecuteEx.
I just tried.
Same result about the SE_ERR_ACCESSDENIED error code (returned in the
"hInstApp" field).
But with ShellExecuteEx, in addition I get an error message box displaying
(1) a copy of the URL used,
(2) The string "La clé de recherche requise n'a été trouvée dans aucun
contexte d'activation actif"
A search on Internet shows that this message seems to correspond to the
"The requested look up key was not found in any activation context"
This message seems to have been very common at the release time of
Internet Explorer 7, and the given "solutions" were (1) Reboot the
computer after IE7 installation, or (2) Uninstall IE7, revert to IE6, and
then reinstall IE7 using Windows Update, or (3) switch to Mozilla Firefox.
(1) My computer (actually all of my three computers running XP have this
problem) have been rebooted at least once every day since the release of
IE7, something like two years ago.
(2) I'm currently having IE8 on my computers, I'm not sure how I can
consider reverting to IE6 and then reinstall IE8 with IE7 eventually
intervening in the middle.
(3) I already use Mozilla Firefox for a time even largely longer than the
release of IE7.
Also, this seems to be a common error on Windows XP, I cannot ask all
users of my application to do repairs like that for the only purpose of
having commands needing ShellExecute working.
Post by Alexander Grigoriev
I wonder also if the verb 'open' got somehow localised in XP SP3 ('ferme'?).
French translation would be "ouvrir", but anyway this string is not
localizable, and also my application perfectly works with the exact same
command on Windows Vista or Windows 7, French Editions.
Post by Alexander Grigoriev
Check if it works with IE as a default browser.
No, it doesn't work better that way.
Gilles
Gingko
2010-01-24 07:00:21 UTC
Permalink
----- Original Message -----
From: "Alexander Grigoriev" <***@earthlink.net>
Newsgroups: microsoft.public.win32.programmer.ui
Sent: Sunday, January 24, 2010 3:58 AM
Subject: Re: Opening URL with ShellExecute returns SE_ERR_ACCESSDENIED on
Windows XP
Post by Alexander Grigoriev
It must be STATUS_SXS_KEY_NOT_FOUND. Its meaning, in the usual Microsoft
tradition, is not explained anywhere.
Do you by any chance have CoInitializeEx(NULL, COINIT_MULTITHREADED) in
your program?
Yes, I have a call like that in my application, can it be a problem ?

Gilles
Alexander Grigoriev
2010-01-24 17:19:52 UTC
Permalink
Shell functions can only work in apartment-threaded COM (or from a thread
with COM not initialized). Spawn a separate thread for a single purpose of
issuing ShellExecute(Ex).

In MULTITHREADED environment, you'll also have problems with the common file
open dialog.
Post by Gingko
----- Original Message -----
Newsgroups: microsoft.public.win32.programmer.ui
Sent: Sunday, January 24, 2010 3:58 AM
Subject: Re: Opening URL with ShellExecute returns SE_ERR_ACCESSDENIED on
Windows XP
Post by Alexander Grigoriev
It must be STATUS_SXS_KEY_NOT_FOUND. Its meaning, in the usual Microsoft
tradition, is not explained anywhere.
Do you by any chance have CoInitializeEx(NULL, COINIT_MULTITHREADED) in
your program?
Yes, I have a call like that in my application, can it be a problem ?
Gilles
Gingko
2010-01-24 23:12:03 UTC
Permalink
Post by Alexander Grigoriev
Shell functions can only work in apartment-threaded COM (or from a thread
with COM not initialized). Spawn a separate thread for a single purpose of
issuing ShellExecute(Ex).
In MULTITHREADED environment, you'll also have problems with the common
file open dialog.
Do you mean that I just have to create a thread with only that instruction
inside and letting the thread terminating right after ?

But in this case, why do I have this problem *only* in Windows XP and NOT in
Windows Vista or Windows 7, using exactly the same application executable ?

Also, as far as I remember, it has been perfectly working in Windows XP in
the same application in the past (undefined past, but probably about 2 years
ago), whereas CoInitializeEx(NULL, COINIT_MULTITHREADED) was already used.

Gilles
Alexander Grigoriev
2010-01-26 04:13:53 UTC
Permalink
Using APARTMENT environment is a requirement for shell calls. Depending on
the OS version, some calls may or may not fail if current COM mode is
MULTITHREADED. Checked build of the OS may enforce this, free (retail) build
may not. If you don't comply, you're on your own. Your program may stop
working after the next windows update. Such is life. Not complying with
system requirement is a major source of compatibility issues and
regressions.
Post by Gingko
Post by Alexander Grigoriev
Shell functions can only work in apartment-threaded COM (or from a thread
with COM not initialized). Spawn a separate thread for a single purpose
of issuing ShellExecute(Ex).
In MULTITHREADED environment, you'll also have problems with the common
file open dialog.
Do you mean that I just have to create a thread with only that instruction
inside and letting the thread terminating right after ?
But in this case, why do I have this problem *only* in Windows XP and NOT
in Windows Vista or Windows 7, using exactly the same application
executable ?
Also, as far as I remember, it has been perfectly working in Windows XP in
the same application in the past (undefined past, but probably about 2
years ago), whereas CoInitializeEx(NULL, COINIT_MULTITHREADED) was
already used.
Gilles
Gingko
2010-01-26 06:08:54 UTC
Permalink
Post by Alexander Grigoriev
Using APARTMENT environment is a requirement for shell calls. Depending on
the OS version, some calls may or may not fail if current COM mode is
MULTITHREADED. Checked build of the OS may enforce this, free (retail)
build may not. If you don't comply, you're on your own. Your program may
stop working after the next windows update. Such is life. Not complying
with system requirement is a major source of compatibility issues and
regressions.
Hello,

I finally found a Microsoft information page about what you said.

http://support.microsoft.com/?scid=kb%3Ben-us%3B287087&x=16&y=15

I rewrote my ShellExecute call in a separate thread and it works.

Thank you very much for your answer.

The most difficult thing to understand, is fact, if knowing exactly what is
an "apartment" in this context (and how it could affect the usage of some
functions like "ShellExecute").

Even apparently described here :
http://msdn.microsoft.com/en-us/library/ms693344%28VS.85%29.aspx ,
it is very hard to find a clear definition of this word in the Microsoft
documentation.

Gilles
Alexander Grigoriev
2010-01-26 15:19:59 UTC
Permalink
In apartment-threaded, all calls executed on the COM object in the thread
where it was created. Calls from other threads are serialised through most
likely SendMessage mechanism. Thus, all methods of a given object execute in
a single thread only.

In multithreaded environment, the calls execute directly.
Post by Gingko
Post by Alexander Grigoriev
Using APARTMENT environment is a requirement for shell calls. Depending
on the OS version, some calls may or may not fail if current COM mode is
MULTITHREADED. Checked build of the OS may enforce this, free (retail)
build may not. If you don't comply, you're on your own. Your program may
stop working after the next windows update. Such is life. Not complying
with system requirement is a major source of compatibility issues and
regressions.
Hello,
I finally found a Microsoft information page about what you said.
http://support.microsoft.com/?scid=kb%3Ben-us%3B287087&x=16&y=15
I rewrote my ShellExecute call in a separate thread and it works.
Thank you very much for your answer.
The most difficult thing to understand, is fact, if knowing exactly what
is an "apartment" in this context (and how it could affect the usage of
some functions like "ShellExecute").
http://msdn.microsoft.com/en-us/library/ms693344%28VS.85%29.aspx ,
it is very hard to find a clear definition of this word in the Microsoft
documentation.
Gilles
Gingko
2010-01-24 00:06:23 UTC
Permalink
Additional comment :

With ShellExecuteEx, GetLastError() returns the error code 14007 :
ERROR_SXS_KEY_NOT_FOUND = (also) "The requested lookup key was not found in
any active activation context"

With ShellExecute, the code returned by GetLastError() was zero.

Gilles
Gingko
2010-01-24 01:02:02 UTC
Permalink
I think that I found a solution, after having made a Google search on
ERROR_SXS_KEY_NOT_FOUND, which bring the following page to my attention :

"Making Static Links Keyboard-Capable, Launching URLs from Your App" by Paul
DiLascia
http://msdn.microsoft.com/en-us/magazine/cc163834.aspx

So I rewrote my call the following way :


CHAR szTemp[256];

sprintf(szTemp, "url.dll,FileProtocolHandler %s",
"http://fr.wikipedia.org/");

int nResult = (int)ShellExecute(hDlg, "open", "rundll32.exe", szTemp, NULL,
SW_SHOWNORMAL);


This looks like fixing the problem on Windows XP.

I now have to check if it still works on Windows Vista and Windows 7.

Gilles
Amitabh
2010-02-10 21:40:01 UTC
Permalink
I am having the same problem. I was using shellexecute in vb6 program, which
has stopped working. How can your solution of rundll32.dll be applied in VB6

I will be thankful if you can suggest a solution for VB6

Amitabh
Post by Gingko
I think that I found a solution, after having made a Google search on
"Making Static Links Keyboard-Capable, Launching URLs from Your App" by Paul
DiLascia
http://msdn.microsoft.com/en-us/magazine/cc163834.aspx
CHAR szTemp[256];
sprintf(szTemp, "url.dll,FileProtocolHandler %s",
"http://fr.wikipedia.org/");
int nResult = (int)ShellExecute(hDlg, "open", "rundll32.exe", szTemp, NULL,
SW_SHOWNORMAL);
This looks like fixing the problem on Windows XP.
I now have to check if it still works on Windows Vista and Windows 7.
Gilles
.
Gingko
2010-02-16 15:38:46 UTC
Permalink
Post by Amitabh
I am having the same problem. I was using shellexecute in vb6 program, which
has stopped working. How can your solution of rundll32.dll be applied in VB6
I will be thankful if you can suggest a solution for VB6
Amitabh
Hello,

It looks like that the best way is probably to spawn a new thread that just
executes ShellExecute and then exits.

Read http://support.microsoft.com/?scid=kb%3Ben-us%3B287087&x=16&y=15

Gilles

Loading...