Search code examples
c++windowsbackgroundexecute

C++'s "system" without wait (Win32)


I have got a program which checks if there's a version update on the server. Now I have to do something like

if(update_avail) {
    system("updater.exe");
    exit(0);
}

but without waiting for "updater.exe" to complete. Otherwise I can't replace my main program because it is running. So how to execute "updater.exe" and immediately exit? I know the *nix way with fork and so on, how to do this in Windows?


Solution

  • Use CreateProcess(), it runs asynchronously. Then you would only have to ensure that updater.exe can write to the original EXE, which you can do by waiting or retrying until the original process has ended. (With a grace interval of course.)