WinExec 和 ShellExecute 之间有哪些区别? [英] Which are the differences between WinExec and ShellExecute?

查看:40
本文介绍了WinExec 和 ShellExecute 之间有哪些区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行另一个应用程序,我想知道是否有理由使用 WinExec 而不是 ShellExecute,反之亦然.

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?

推荐答案

WinExec 早已弃用,仅出于向后兼容的原因保留.它用于启动可执行文件.不要使用它,因为它已被弃用.如文档中所述:

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:

提供此功能只是为了与 16 位 Windows 兼容.应用程序应使用 CreateProcess 函数.

This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.

ShellExecute 未弃用,但也不应使用,因为它无法正确报告错误.

ShellExecute is not deprecated, but also should not be used since it cannot report errors properly.

使用 ShellExecuteEx 来执行 shell 动词.

Use ShellExecuteEx to execute shell verbs.

如果您想创建一个进程,并且您知道可执行文件名,请使用CreateProcess.除非你需要执行提升,在这种情况下你需要 ShellExecuteExrunas 动词.

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.

这篇关于WinExec 和 ShellExecute 之间有哪些区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆