CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Location
    Maryland
    Posts
    6

    Having trouble with CreateProcess

    CreateProcess fails with GetLastError = 87 message The parameter is incorrect.

    Which parameter? I've tried specifying the filename as app name and as the command line and still get the same error. Running VC++ 6.0 in WIN98.

    code sample follows:
    (See attached test code for full test program.)

    char szInExec[] = "C:\\testbat.bat";

    sprintf(szParams, "%s %s", szInExec, szInExec);

    ret = CreateProcess(
    NULL, // LPCTSTR lpApplicationName, // pointer to name of executable module

    szParams, // LPTSTR lpCommandLine, // pointer to command line string

    NULL, // LPSECURITY_ATTRIBUTES lpProcessAttributes, // process security attributes

    NULL, // LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes

    NULL, // BOOL bInheritHandles, // handle inheritance flag

    CREATE_NEW_CONSOLE, // DWORD dwCreationFlags, // creation flags

    NULL, // LPVOID lpEnvironment, // pointer to new environment block

    NULL, // LPCTSTR lpCurrentDirectory, // pointer to current directory name

    NULL, // LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO

    &ProcInfo // LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
    );
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Having trouble with CreateProcess

    Originally posted by lsimon
    CreateProcess fails with GetLastError = 87 message The parameter is incorrect.

    Which parameter? I've tried specifying the filename as app name and as the command line and still get the same error. Running VC++ 6.0 in WIN98.

    code sample follows:
    (See attached test code for full test program.)

    char szInExec[] = "C:\\testbat.bat";
    Are batch files considered executable files? This may be your problem -- CreateProcess supposedly works only on executable files, not batch files. Maybe someone else can shed more light on this.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    720
    Try:
    Code:
    PROCESS_INFORMATION ProcInfo={0};
    STARTUPINFO StartupInfo={0};
    
    //for win98 -- command.com.
    //use GetSystemDirectory().
    CreateProcess("C:\\windows\\system32\\cmd.exe", "/c C:\\testbat.bat", 0, 0, 0, CREATE_NEW_CONSOLE, 0, 0, &ProcInfo, &StartupInfo);

  4. #4
    Join Date
    Oct 2002
    Location
    St. Louis
    Posts
    27
    Here is some info from MSDN:

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    // Start the child process.
    if( !CreateProcess( NULL, // No module name (use command line).
    "c:\\joe\\project\\temp\\playwmf.exe", // Command line.
    NULL, // Process handle not inheritable.
    NULL, // Thread handle not inheritable.
    TRUE, // Set handle inheritance to FALSE.
    0, // No creation flags.
    NULL, // Use parent's environment block.
    "c:\\joe\\project\\temp\\", // Use parent's starting
    directory.
    &si, // Pointer to STARTUPINFO structure.
    &pi ) // Pointer to PROCESS_INFORMATION structure.
    )
    {
    //ErrorExit( "CreateProcess failed." );
    int i = 101;
    }

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

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

  5. #5
    Join Date
    Oct 2003
    Location
    Maryland
    Posts
    6
    Thank you for your prompt replies.

    Declaring and Initializing the startinfo was what was required. The batch file starts fine. The attached file contains the debugged version with the printfs' cleaned up.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured