Search code examples
c++windowsshellexecute

C++ ShellExecute is not working the same way as cmd.exe


I'm running this command

w_icrcom.exe j11 hola

from a command prompt and it is working properly, the exe is running using the arguments.

But when I'm doing the same from a C++ program the w_icrcom.exe is behaving differently. I'm getting an error saying that "abnormal program termination". This though is happening only when you pass arguments to 'w_icrcom.exe'.

It seems to me, that when I execute a command everything is fine, but when some other program is trying to execute the same command it doesn't work and I'm getting the "abnormal program execution" error.

I tried the same set up on ShellExecute calling the notepad.exe and passing arguments and it worked fine. Is there any logical explanation on this issue?

string test_var = ("j11 hola");
ShellExecute(0, "open", "C:\\Users\\PC\\Desktop\\My First\\connect\\bin\\w_icrcom.exe", test_var.c_str(), 0, SW_SHOW);

Solution

  • The next to last parameter of ShellExecute is the 'working directory'. It might need to be set to whatever is the current directory in the cmd prompt that is working.