Discussion:
How can I test failure in ShellExecuteEx with UAC active?
(too old to reply)
Davide Angeli
2010-12-20 15:27:34 UTC
Permalink
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
2010-12-20 15:52:19 UTC
Permalink
Post by Davide Angeli
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
Davide Angeli
2010-12-20 16:31:19 UTC
Permalink
Post by David Lowndes
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
David Lowndes
2010-12-20 16:56:25 UTC
Permalink
Post by Davide Angeli
Post by David Lowndes
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.
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
2010-12-20 17:22:21 UTC
Permalink
Post by David Lowndes
Post by Davide Angeli
Post by David Lowndes
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.
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
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
2010-12-20 18:29:38 UTC
Permalink
Post by Davide Angeli
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

Leo Davidson
2010-12-20 16:08:00 UTC
Permalink
Post by Davide Angeli
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
2010-12-20 16:42:12 UTC
Permalink
Post by Leo Davidson
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
Loading...