Programming Tips - How do I use WinExec() ?

Date: 2010mar19 Updated: 2015dec9 Language: C/C++ OS: Windows Q. How do I use WinExec() ? A. The documentation says its "obsolete" but its an easy way to launch another program from yours. Some examples... Launch Notepad (its in your PATH so you don't need specify it its full file name):
WinExec("notepad", SW_SHOWNORMAL);
Launch Windows Calendar:
WinExec("c:\\Program Files\\Windows Calendar\\wincal.exe", SW_SHOWNORMAL);
Check if it failed:
if (WinExec(szFile, SW_SHOWNORMAL) <= 31) { MessageBox(... "failed"...); }
Check if it worked:
if (WinExec(szFile, SW_SHOWNORMAL) > 31) { // Worked }
Use SW_HIDE if you don't want a popup:
bool run(LPCSTR cmd) { return WinExec(cmd, SW_HIDE) > 31; } // Example: run("net start snmp");
There is also ShellExecute http://www.google.com/search?q=ShellExecute See also http://www.davekb.com/search.php?target=ExecCommand