Hiding the process window, why isn't it working?

后端 未结 1 893
遥遥无期
遥遥无期 2021-01-18 00:20

I have tried several things now to hide the window of a new process (in this case it\'s just notepad.exe for testing), but it just won\'t work regardless of what I try.

相关标签:
1条回答
  • 2021-01-18 00:41

    In my experience, the following works whenever I fire up "cmd.exe".

    info.CreateNoWindow = true;
    info.UseShellExecute = false;                                
    

    It doesn't seem to work with "notepad.exe". It fails with other apps too, like "excel.exe" and "winword.exe".

    This works, however:

    ProcessStartInfo info = new ProcessStartInfo("notepad.exe");
    
    info.WindowStyle = ProcessWindowStyle.Hidden;
    
    Process proc = Process.Start(info);
    

    From MSDN:

    A window can be either visible or hidden. The system displays a hidden window by not drawing it. If a window is hidden, it is effectively disabled. A hidden window can process messages from the system or from other windows, but it cannot process input from the user or display output. Frequently, an application may keep a new window hidden while it customizes the window's appearance, and then make the window style Normal. To use ProcessWindowStyle.Hidden, the ProcessStartInfo.UseShellExecute property must be false.

    When I tested it, I didn't have to set UseShellExecute = false.

    0 讨论(0)
提交回复
热议问题