2012-10-09 48 views
4

錯誤代碼18在CreateProcess之後。爲什麼?CreateProcess錯誤代碼18

#include <iostream> 
#include <windows.h> 
#include <stdio.h> 
#include <tchar.h> 
using namespace std; 

int main() 
{ 
    STARTUPINFO si; 
    PROCESS_INFORMATION pi; 
    ZeroMemory(&si, sizeof(si)); // macro fills a block of memory with zeros 
    ZeroMemory(&pi, sizeof(pi)); 
    si.cb = sizeof(si); 

    BOOL create_proc = CreateProcess(L"c:\\windows\\system32\\cmd.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); 
    //printf("Error (%d)\n", GetLastError()); 
    if(!create_proc) 
     printf("CreateProcess failed (%d).\n", GetLastError()); 

    // Wait until child process exits. 
    WaitForSingleObject(pi.hProcess, INFINITE); 

    // Close process and thread handles. 
    CloseHandle(pi.hProcess); 
    CloseHandle(pi.hThread); 

    //check 
    printf("Error (%d)\n", GetLastError()); 

    return 0; 
} 
+0

如果有任何安慰......代碼對我來說不會錯誤。它可能是權限,磁盤空間或其他原因? – johnnycrash

回答