Search code examples
c++shellbatch-fileshellexecutemsg

C++ ShellExecute msg issue


I have a .bat file which sends a local message. When I run it myself (double-click) it works (a message pops out). It doesn't work when I launch the .bat with ShellExecute(); though. What could be the case? Here's the code:

message.bat

msg * hello

main.cpp

#include <windows.h>

int main()
{
    ShellExecute(NULL, "open", "message.bat", NULL, NULL, 0);
}

Other things in .bat such as start <something>, shutdown, etc. work with ShellExecute();.

EDIT I can't even run msg with system();. It only works manually from cmd or a .bat file.


Solution

  • Could it be that you're compiling it as 32bit on 64bit OS? in that case it will not be allowed to run msg.exe