在服务进程A里通过CreateProcess的方式去启动进程B,已经将fdwCreate参数设置为CREATE_NEW_CONSOLE标志了,为何进程B虽然被正常启动,但还是没有控制台界面。
而如果我把服务进程换成是一个普通的控制台进程,在此进程里再去以CreateProcess的方式启动进程B,进程B就有界面了?

解决方案 »

  1.   

    不是吧,如果B进程是一个QQ.exe,你设置了CREATE_NEW_CONSOLE 难道启动会变成控制台的界面?
      

  2.   

    Creation of a Console
    The system creates a new console when it starts a console process, a character-mode process whose entry point is the main function. For example, the system creates a new console when it starts the command processor. When the command processor starts a new console process, the user can specify whether the system creates a new console for the new process or whether it inherits the command processor's console.A process can create a console by using one of the following methods:
    A GUI or console process can use the CreateProcess function with CREATE_NEW_CONSOLE to create a console process with a new console. (By default, a console process inherits its parent's console, and there is no guarantee that input is received by the process for which it was intended.) 
    A graphical user interface (GUI) or console process that is not currently attached to a console can use the AllocConsole function to create a new console. (GUI processes are not attached to a console when they are created. Console processes are not attached to a console if they are created using CreateProcess with DETACHED_PROCESS.) 
    Typically, a process uses AllocConsole to create a console when an error occurs requiring interaction with the user. For example, a GUI process can create a console when an error occurs that prevents it from using its normal graphical interface, or a console process that does not normally interact with the user can create a console to display an error.A process can also create a console by specifying the CREATE_NEW_CONSOLE flag in a call to CreateProcess. This method creates a new console that is accessible to the child process but not to the parent process. Separate consoles enable both parent and child processes to interact with the user without conflict. If this flag is not specified when a console process is created, both processes are attached to the same console, and there is no guarantee that the correct process will receive the input intended for it. Applications can prevent confusion by creating child processes that do not inherit handles of the input buffer, or by enabling only one child process at a time to inherit an input buffer handle while preventing the parent process from reading console input until the child has finished.Creating a new console results in a new console window, as well as separate I/O screen buffers. The process associated with the new console uses the GetStdHandle function to get the handles of the new console's input and screen buffers. These handles enable the process to access the console.When a process uses CreateProcess, it can specify a STARTUPINFO structure, whose members control the characteristics of the first new console (if any) created for the child process. The STARTUPINFO structure specified in the call to CreateProcess affects a console created if the CREATE_NEW_CONSOLE flag is specified. It also affects a console created if the child process subsequently uses AllocConsole. The following console characteristics can be specified:
    Size of the new console window, in character cells 
    Location of the new console window, in screen pixel coordinates 
    Size of the new console's screen buffer, in character cells 
    Text and background color attributes of the new console's screen buffer 
    Display name for the title bar of the new console's window 
    The system uses default values if the STARTUPINFO values are not specified. A child process can use the GetStartupInfo function to determine the values in its STARTUPINFO structure.A process cannot change the location of its console window on the screen, but the following console functions are available to set or retrieve the other properties specified in the STARTUPINFO structure.
      

  3.   

    PROCESS_INFORMATION pi;

    STARTUPINFO si = {0};
    si.cb = sizeof(STARTUPINFO);
    ....
    if(CreateProcess(NULL, _T(".\\A.exe"), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
    {
    AllocConsole();
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    }
      

  4.   

    没搞过这,还是不明白
    如果B进程是一个QQ.exe,你设置了CREATE_NEW_CONSOLE 难道启动会变成控制台的?
      

  5.   


    可能LZ说的模糊
    但应该是在说进程A是服务进程,进程B是控制台进程
    ...
      

  6.   

    我这边可以启动一个console啊,只是没有关联数据流而已