ShellExecute和CMD命令有什么区别?

时间:2015-03-11 16:01:18

标签: c++ cmd shellexecute

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

因为我有一个奇怪的问题,我有一个带有参数的.exe。当我用CMD的参数调用这个exe时,它正常工作。但是当我从ShellExecute执行相同的操作时,程序会返回错误。

可能有什么不对?

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

1 个答案:

答案 0 :(得分:1)

是一个非常大的差异。

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

对于CMD,请参阅Tim Hill(1998)的 Windows NT Shell Scripting,第2章,Windows NT命令Shell ,可从MS的网站获得(只有该章免费提供)。 CMD对传递给CreateProcessEx的内容进行了预处理。 CMD也有自己的ShellExecute仿真,但是它在ShellExecute的Windows 95规则下,而不是经常更新的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.