title: C++ CreateProcess error-code 2 ("ERROR_FILE_NOT_FOUND") on Windows 7 (64)
body: <p>I'm trying to create a simple program to test CreateProcess() function in C/C++ on Windows 7 (64). When i pass the CommandLine ("szCmdline") parameter directly it works fine, but if i try to send parameters by getting it from argv and pass to a funcion i'm getting the "Error code 2 ("ERROR_FILE_NOT_FOUND")" at runtime.</p>
  
  <p>I was looking for a solution and found that "<a href="https://stackoverflow.com/questions/7003981/createprocess-fails-under-windows-7">CreateProcess-fails-under-windows-7</a>" on this forum, but it seems not work for me or i'm doing something wrong.</p>
  
  <p>This is the NewProcess() code:</p>
  
  <pre><code>void NewProcess(TCHAR **cmd){
  
      printf("Argv Inside funcion: %s\n",cmd[1]);
      STARTUPINFO si;
      PROCESS_INFORMATION pi;
  
      ZeroMemory( &amp;si, sizeof(si) );
      si.cb = sizeof(si);
      ZeroMemory( &amp;pi, sizeof(pi) );
      // Start the child process. 
      if( !CreateProcess( NULL,   // No module name (use command line)
          cmd[1],         // Command line
          NULL,           // Process handle not inheritable
          NULL,           // Thread handle not inheritable
          FALSE,          // Set handle inheritance to FALSE
          0,              // No creation flags
          NULL,           // Use parent's environment block
          NULL,           // Use parent's starting directory 
          &amp;si,            // Pointer to STARTUPINFO structure
          &amp;pi )           // Pointer to PROCESS_INFORMATION structure
      ) 
      {
          printf( "CreateProcess failed (%d).\n", GetLastError() );
          return;
      }
  
      printf("Process ID: %d Started",pi.dwProcessId);
      // Wait until child process exits.
      WaitForSingleObject( pi.hProcess, INFINITE );
      printf("\nProcess ID: %d Terminated!",pi.dwProcessId);
  
      // Close process and thread handles.
      CloseHandle( pi.hProcess );
      CloseHandle( pi.hThread );
  }
  </code></pre>
  
  <p>And the Main funcion code:</p>
  
  <pre><code>void main(int argc, TCHAR *argv[])
  {
      printf("Argv outside function: %s\n",argv[1]);
      //LPTSTR szCmdline = _tcsdup(TEXT("C:\\Windows\\system32\\calc.exe"));  &lt;-- **It works fine**
  
      NewProcess(argv);  // &lt;-- **It doesn't works**
  }
  </code></pre>
  
  <p>At runtime, cmd and argv contains the same data but it fails at CreateProcess() call.</p>
  
  <p>Result:</p>
  
  <pre><code>E:\C++\VISUAL_STUDIO\NewTest&gt; newtest.exe "C:\Windows\System32\calc.exe"
  Argv outside function: C:\Windows\System32\calc.exe
  Argv Inside funcion: C:\Windows\System32\calc.exe
  CreateProcess failed (2).
  </code></pre>
  
  <p>I tested with "C:\\windows\\system32\\calc.exe", %windir%\system32\calc.exe , "C:\Windows\SysNative\calc.exe"</p>
  
  <p>Any idea?</p>
  
  <p>Thanks advice</p>