system()
just calls CreateProcess()
internally, so you can do the same thing directly, eg:
int my_system(LPCTSTR command)
{
TCHAR szComSpec[MAX_PATH+1];
DWORD dwLen = GetEnvironmentVariable(_T("COMSPEC"), szComSpec, MAX_PATH);
if ((dwLen == 0) || (dwLen > MAX_PATH))
return -1;
LPTSTR szCmdLine = (LPTSTR) LocalAlloc(LPTR, (dwLen+lstrlen(command)+9) * sizeof(TCHAR));
if (!szCmdLine)
return -1;
wsprintf(szCmdLine, _T("\"%s\" /C \"%s\""), szComSpec, command);
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));
BOOL bRet = CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if (bRet)
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
LocalFree(szCmdLine);
return (bRet) ? 0 : -1;
}