Reputation: 880
I need to execute another application and I'm wondering if there's a reason why I should use WinExec
instead of ShellExecute
or vice versa.
Which are differences between two methods? Is there one that should be preferred?
Upvotes: 10
Views: 7418
Reputation: 612993
WinExec
is long deprecated and retained only for backwards compatibility reasons. It is used to start executables. Don't use it, due to its deprecation. As stated in the documentation:
This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.
ShellExecute
is not deprecated, but also should not be used since it cannot report errors properly.
Use ShellExecuteEx
to execute shell verbs.
If you wish to create a process, and you know the executable file name, use CreateProcess
. Unless you need to execute elevated in which case you need ShellExecuteEx
with the runas
verb.
Upvotes: 16