I am trying to run an executable in background written in C++ in Windows 10. The program does not have any GUI. I tried this
window = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(window,0);
But although it does work on Windows 7 and opens and instantly closes the console, and the executable runs in background, on Windows 10 it opens a console and the console stays open. If I run the .exe with run /B main.exe I have to keep the console open in order for the program to keep running, and if I close the cmd console execution stops.
Is there a way to programatically run the file in background? I am aware that I can run it in background using vbscript, but I would like to avoid that.
createprocessarequires me to give the path to the executable. I would like to have it all in one single program, both the option to run in background as well as the rest of the main program.CreateProcessto execute any program you have the path to, including itself. Or (not really knowing the problem you're attempting to solve) perhaps what you really want is to use threads to run some parts of your program in the "background"?CreateProcess()has flags to hide the process it spawns. If you spawn a console app, you can tell it to hide the console window that is created. You don't need to hunt for the window afterwards and hide it manually