ShellExecute和CMD命令之间有什么区别,如果有的话

What is the difference between ShellExecute and CMD commands, if any?

本文关键字:如果 区别 什么 CMD 命令 之间 ShellExecute      更新时间:2023-10-16

执行方面,这两个命令之间有什么区别,除了一个用于C++,另一个是CMD的事实?

因为我遇到了一个奇怪的问题,所以我有一个.exe,它需要争论。当我用CMD的参数调用这个exe时,它工作正常。但是当我从 ShellExecute 做同样的事情时,程序会返回错误。

可能出了什么问题?

ShellExecute(
NULL,
_T("open"),
_T("C:\connect\connect.exe"),
_T("J11"),
NULL,
SW_SHOW);

是的,差异非常大。

CMD处理您键入的内容,然后将其传递给CreateProcessEx。CMD的"开始"命令,运行对话框或双击文件,将传递给ShellExecuteEx函数之一,该函数又调用CreateProcessEx。

有关CMD,请参阅Windows NT Shell Scripting,第2章,Tim Hill(1998)的Windows NT Command Shell,可从MS的网站获得(只有该章是免费提供的)。CMD对传递给CreateProcessEx的内容进行了详细的预处理。CMD也拥有ShellExecute的仿真,但它是在Windows 95规则下ShellExecute,而不是经常更新的shell32实现。

有关 ShellExecute,请参阅ShellExecuteEx文档。

要查看CreateProcessEx规则,请参阅其文档。

我打算粘贴规则,但CMD跑到页面。

返回值告诉您命令不起作用的原因。

返回值

如果成功,则返回大于 32

的值,否则返回小于或等于 32 的错误值。下表列出了错误值。返回值转换为 HINSTANCE,以便向后兼容 16 位 Windows 应用程序。然而,它不是一个真正的HINSTANCE。返回的 HINSTANCE 唯一可以做的是将其转换为 int 并将其与值 32 或下面的错误代码之一进行比较。

0 The operating system is out of memory or resources. 
ERROR_FILE_NOT_FOUND The specified file was not found. 
ERROR_PATH_NOT_FOUND The specified path was not found. 
ERROR_BAD_FORMAT The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image). 
SE_ERR_ACCESSDENIED The operating system denied access to the specified file. 
SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid. 
SE_ERR_DDEBUSY The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed. 
SE_ERR_DDEFAIL The DDE transaction failed. 
SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out. 
SE_ERR_DLLNOTFOUND The specified DLL was not found. 
SE_ERR_FNF The specified file was not found. 
SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable. 
SE_ERR_OOM There was not enough memory to complete the operation. 
SE_ERR_PNF The specified path was not found. 
SE_ERR_SHARE A sharing violation occurred. 
相关文章: