Neka
Neka

Reputation: 1664

wxExecute can't execute file that needs admin permissions UAC

From wxWidgets application I try to run installer, made with NSIS, in silent mode (/S flag). Got this error:

Execution of command: "C:\somecommand.exe" failed (error 0: Операция завершена успешно / Successful).

When I run installer silently from command line, I got UAC popup, but when I execute it from wxWidget application I got only this error. And what this error means? Like "Fatal Error: All is fine".

In NSIS script I have RequestExecutionLevel admin, because I really need it to have ability to install program in directories like Program Files.

Upvotes: 0

Views: 722

Answers (1)

Anders
Anders

Reputation: 101606

To start a Windows application that requires elevation you must use ShellExecute and not CreateProcess, CreateProcess will just fail with a elevation required error.

I would imagine that wxLaunchDefaultApplication uses ShellExecute internally but it seems a bit risky to rely on that so you might as well use a ifdef:

#ifdef __WINDOWS__  // __WXMSW__
ShellExecute(0, 0, pathtoexe, parameters, 0, SW_SHOW);
#else
wxExecute(something);
#endif

Upvotes: 1

Related Questions