Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which are the differences between WinExec and ShellExecute?

Tags:

winapi

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?

like image 328
Hwau Avatar asked May 08 '15 15:05

Hwau


1 Answers

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.

like image 84
David Heffernan Avatar answered Jan 02 '23 17:01

David Heffernan