Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I test failure in ShellExecuteEx with UAC active?

389 views
Skip to first unread message

Davide Angeli

unread,
Dec 20, 2010, 10:27:34 AM12/20/10
to
I run an application with ShellExecuteEx on Windows 7.
Windows shows me the UAC prompt asking me if the program is
certified.
If I choose No, the program is stopped but ShallExecuteEx returns
always true.

How can I test this condition (I need to know that the user refuses
the program execution)?

Thanks
Davide

David Lowndes

unread,
Dec 20, 2010, 10:52:19 AM12/20/10
to
>I run an application with ShellExecuteEx on Windows 7.
>Windows shows me the UAC prompt asking me if the program is
>certified.

Davide,

Are you specifying the "RunAs" verb when you use ShellExecuteEx?

In a quick test, when RunAs is specified and the user says No to the
UAC dialog, ShellExecuteEx fails for me.

Dave

Leo Davidson

unread,
Dec 20, 2010, 11:08:00 AM12/20/10
to
On Dec 20, 3:27 pm, Davide Angeli <davideang...@gmail.com> wrote:

> If I choose No, the program is stopped but ShallExecuteEx returns
> always true.

I think you're using ShellExecuteEx incorrectly, or there's a detail
you haven't told us (e.g. you are executing a document and not a
program or something).

I just tried this:

int wmain(int argc, TCHAR *lpszArgv[])
{
::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
COINIT_DISABLE_OLE1DDE);

SHELLEXECUTEINFO sei = {0};
sei.cbSize = sizeof(sei);
sei.fMask = SEE_MASK_NOASYNC;
sei.lpFile = L"C:\\Windows\\RegEdit.exe";
sei.lpDirectory = L"C:\\Windows";
sei.nShow = SW_SHOW;

BOOL fResult = ::ShellExecuteEx(&sei);
DWORD dwErr = ::GetLastError();

wprintf(L"Result:%s, Err:0x%lx, hInstApp:0x%lx\n",
fResult?L"TRUE":L"FALSE",
dwErr,
sei.hInstApp);

::CoUninitialize();

return 0;
}

If I cancel the UAC prompt it prints:

Result:FALSE, Err:0x4c7, hInstApp:0x5

GetLastError returning 0x4c7 means ERROR_CANCELLED.

hInstApp being set to 5 means SE_ERR_ACCESSDENIED.

Davide Angeli

unread,
Dec 20, 2010, 11:31:19 AM12/20/10
to
> Are you specifying the "RunAs" verb when you use ShellExecuteEx?
>
> In a quick test, when RunAs is specified and the user says No to the
> UAC dialog, ShellExecuteEx fails for me.
>
> Dave

Dave,
you are right! Specifing "RunAs" the ShellExecuteEx call fails in that
case.

Thank you

Davide

Davide Angeli

unread,
Dec 20, 2010, 11:42:12 AM12/20/10
to
On 20 Dic, 17:08, Leo Davidson <leonudeldavid...@gmail.com> wrote:
> I think you're using ShellExecuteEx incorrectly, or there's a detail
> you haven't told us (e.g. you are executing a document and not a
> program or something).

What I'm doing different is that I'm specifing SEE_MASK_NO_CONSOLE in
the fMask (you are using SEE_MASK_NOASYNC instead) . Could be this the
problem? However putting "RunEs" in the verb it seems functioning.

Davide

David Lowndes

unread,
Dec 20, 2010, 11:56:25 AM12/20/10
to

Hmm.

Is the situation perhaps that the application you're running in fact
runs, and in turn it tries to start another process, and its that that
was prompting for elevation?

By specifying RunAs you'd be shifting the elevation to the
intermediate process.

Dave

Davide Angeli

unread,
Dec 20, 2010, 12:22:21 PM12/20/10
to

Effectivly could be because the application that I'm running is a
small setup (built with InnoSetup). I don't know how InnoSetup works
but I suppose that internally it could create a new intermediate
process elevated so I understand why you are perplexed.

Davide


David Lowndes

unread,
Dec 20, 2010, 1:29:38 PM12/20/10
to
>Effectivly could be because the application that I'm running is a
>small setup (built with InnoSetup). I don't know how InnoSetup works
>but I suppose that internally it could create a new intermediate
>process elevated so I understand why you are perplexed.

Installers often do that. I think that would explain the behaviour you
got.

Dave

0 new messages