How could i Create a process with hiding the proce

2019-06-13 07:17发布

问题:

 /* CreateProcess initialization */
 STARTUPINFO si;
 PROCESS_INFORMATION pi;

 memset(&si, 0, sizeof(si));
 memset(&pi, 0, sizeof(pi));
 si.cb = sizeof(si);

 long ret;
 // si.wShowWindow = SW_HIDE;
 // hide process window.... // run in background..

 si.dwFlags = STARTF_USESHOWWINDOW;
 si.wShowWindow = SW_HIDE;

 if (!CreateProcess(0, exe,
        0, 0, 1, NORMAL_PRIORITY_CLASS, 0, 0, &si, &pi)) {
    return;
 }
 //int prez = WaitForSingleObject(pi.hProcess, INFINITE);

 //CloseHandle(pi.hProcess);

回答1:

You can attempt to set the dwFlags member of your STARTUPINFO structure to STARTF_USESHOWWINDOW and the wShowWindow member to SW_HIDE.

This will make CreateProcess() pass 0 as the nCmdShow parameter of WinMain. However, not all Windows application are well behaved and use this value to the initial call to ShowWindow().



回答2:

It's not you, the creator of the new process, that registers the new process into the task bar. It's the new process that creates a top-level window that decides whether or not to be in the taskbar. This decision is based on the extended style of that top-level window, which is determined by the new process.

In other words, you'd have to poke at the top-level window in this other process in order to do this.



回答3:

You can find the window associated with the started process (see FindWindow and EnumWindows), and call ShowWindow function with SW_HIDE. Alternatively you can modify the extended style of the window by removing WS_EX_APPWINDOW and adding WS_EX_TOOLWINDOW.

The simplest way is still to use STARTUPINFO as described in the first answer, if the started process respects the setting.