我需要执行另一个应用程序,我想知道是否有理由使用 WinExec
而不是 ShellExecute
或相反亦然。
两种方法有哪些区别?有没有应该首选的?
最佳答案
WinExec
长期弃用并仅出于向后兼容的原因保留。它用于启动可执行文件。不要使用它,因为它已被弃用。如文档中所述:
This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.
ShellExecute
未弃用,但也不应使用,因为它无法正确报告错误。使用
ShellExecuteEx
执行shell动词。如果您想创建一个进程,并且您知道可执行文件的名称,请使用
CreateProcess
.除非你需要执行提升,在这种情况下你需要 ShellExecuteEx
与 runas
动词。
关于winapi - WinExec 和 ShellExecute 之间有哪些区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30127504/