c++processcreateprocess

CreateProcess not working


I am having problems with getting the following code to work in C++ (VC++ console app). It simply doesn't create the process, but it prints out the error text.

static void main(){
    char *hotkeyexe = "cmd";
    PROCESS_INFORMATION pi;
    STARTUPINFO si;

    if(!CreateProcess(hotkeyexe, "", 0, 0, 0, 0, 0, 0, &si, &pi))
        printf("error");
        scanf("%d");
    }
}

Solution

  • You need to zero out STARTUPINFO.

    ZeroMemory(&si, sizeof(si));