#include <process.h> bool isMyServiceInstalled() { LPCSTR scExe = "c:\\windows\\system32\\sc.exe"; LPCSTR args[] = { "sc", "query", "MyService", NULL }; const intptr_t result = spawnv(P_WAIT, scExe, args); return result == 0; }
Programming Tips - Win32: Use spawnv() to easily run a process
Date: 2023jan18
Language: C/C++
Q. Win32: Use spawnv() to easily run a process
A. If you want specify a known number of arguments to an executable to run,
using spawnv() is a great choice. You area passing the arguments directly to
the main(argv, argv) of the other program. You don't need to be concerned
with the shell and quoting.
Here is an example running the Windows "sc" to see if a service is
installed.