Originally Posted by
anduril462
I think iMalc is right, ShellExecute is the better function to use in this case, and I recommend following his advice, as he is much better at Windows programming than I am.
That being said, if you read the documentation for _spawnl carefully, you will notice that it's _P_NOWAIT, with a leading underscore. That may matter. You also may want to try using _P_WAIT, which should make the parent process wait for the child process to finish before continuing. Just a guess, but there may be an issue where the parent spawns the child process and terminates, cleaning up resources (that the child inherited when it was spawned) that are needed to play sounds, before the child process can actually play any sound.
Originally Posted by
iMalc
Try using ShellExecute instead.
Thanks for the responses, I fixed the code now and I'm able to execute the VBSscript and the sound plays. Here was the code I ended up with after adding ShellExecute.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#include <windows.h>
int main()
{
if ( ((int)(ShellExecute(NULL, NULL, "C:\\CProjects\\WARNING.vbs", NULL, NULL, SW_SHOWNORMAL))) < 33 )
{
fprintf(stderr, "Error : %s", strerror(GetLastError()));
}
return 0;
}
I followed Microsoft's instructions by casting the return value to an int, and testing to see if it was not above 32 for when it failed.