CreateProcess doesn't pass command line arguments

前端 未结 8 2171
梦谈多话
梦谈多话 2020-12-01 10:20

Hello I have the following code but it isn\'t working as expected, can\'t figure out what the problem is.

Basically, I\'m executing a process (a .NET process) and pa

8条回答
  •  日久生厌
    2020-12-01 11:08

    Below is a cut down version of the code used by the Zeus IDE to run external processes:

    bool createProcess(const char *pszTitle, const char *pszCommand)
    {
      STARTUPINFO StartInfo;
    
      memset(&StartInfo, 0, sizeof(StartInfo));
    
      StartInfo.cb      = sizeof(StartInfo);
      StartInfo.lpTitle = (pszTitle) ? (char *)pszTitle : (char *)pszCommand;
    
      StartInfo.wShowWindow = SW_NORMAL;
      StartInfo.dwFlags    |= STARTF_USESHOWWINDOW;
    
      if (CreateProcess(0, (char *)pszCommand, 
                        0, 0, TRUE,
                        CREATE_NEW_PROCESS_GROUP, 0, 0, 
                        &StartInfo, &ProcessInfo))
      {
        lErrorCode = 0;
      }
      else
      {
        lErrorCode = GetLastError();
      }
    
      return (lErrorCode == 0);
    }
    

    The pszCommand would be the full executable path and file name and arguments so for example:

    pszCommand = "D:\\email\\smtp.exe name@example.com";
    

    From what I can tell, the only real difference between the two is that in the Zeus example, the dwCreationFlags argument is set to the CREATE_NEW_PROCESS_GROUP value.

提交回复
热议问题