-1

Execution wise, is any difference between those two commands, except the fact that the one is for C++ and the other is the CMD?

Because I'm having a strange problem, I have an .exe that it takes arguments. When I call this exe with it's arguments from the CMD it is working normally. But when I do the same thing from ShellExecute the program returns an error.

What could be wrong?

ShellExecute(
NULL,
_T("open"),
_T("C:\\connect\\connect.exe"),
_T("J11"),
NULL,
SW_SHOW);
  • 1
    I don't think there's not enough information in this question to figure out the answer. Most likely, there's something wrong with one of the `ShellExecute` arguments (not the arguments to your executable, but to the function itself). – Austin Mullins Mar 11 '15 at 16:06
  • 2
    In addition to what @AustinMullins suggested, there's a good chance that quoting (parameters and/or paths) is going to come into play. – Mr. Llama Mar 11 '15 at 16:07
  • 1
    You ask us what's wrong with your ShellExecute() code, but didn't include the code. How are we to debug code we can't see? – Ken White Mar 11 '15 at 16:09
  • Make sure you escape your paths if you use '\' in a string literal. – drescherjm Mar 11 '15 at 16:12
  • That code does not show arguments being passed, which means that the problem is that you're not passing the arguments. (Or you didn't post your actual code.) If you want help here, **post your real code**. Otherwise, please stop wasting our time. – Ken White Mar 11 '15 at 16:31
  • "J11" isn't the argument? – Austin Mullins Mar 11 '15 at 21:59

1 Answers1

2

Yes a very big difference.

CMD processes what you type then passes it to CreateProcessEx. CMD's Start command, run dialog, or double clicking a file, gets passed to one of the ShellExecuteEx functions, which in turn calls CreateProcessEx.

For CMD see Windows NT Shell Scripting, Chapter 2, The Windows NT Command Shell by Tim Hill (1998), available from MS's web site (only that chapter is available for free). CMD's preprocessing of what is passed to CreateProcessEx is detailed. CMD also does it own emulation of ShellExecute but it is under Windows 95 rules for ShellExecute, rather than the frequently updated shell32 implementation.

For ShellExecute see the ShellExecuteEx documentation.

To see CreateProcessEx rules see it's documentation.

I was going to paste the rules, but CMD's ran to pages.

The Return value tells you why your command isn't working.

Return Value

Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. The only thing that can be done with the returned HINSTANCE is to cast it to an int and compare it with the value 32 or one of the error codes below.

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. 
Community
  • 1
  • 1
Serenity
  • 46
  • 2