0

I have a couple of old windows programs that we still need to use. Both are designed to run from batch files with command line options so using Process to start and monitor them works fine.

Both programs display progress windows after starting and I would like to hide those windows but they don't seem to respond to the Process setting that control window display.

enter image description here

ProcessStartInfo info = new ProcessStartInfo() {
    FileName = appName,
    Arguments = arguments,
    RedirectStandardError = true,
    RedirectStandardOutput = true,
    WorkingDirectory = workingDirectory,
    UseShellExecute = false,
    CreateNoWindow = true,
    WindowStyle = ProcessWindowStyle.Hidden
};

StringBuilder errorData = new StringBuilder(OUTPUT_SIZE);
StringBuilder outputData = new StringBuilder(OUTPUT_SIZE);

using (Process process = new Process { StartInfo = info }) {
    process.ErrorDataReceived += new DataReceivedEventHandler((sender, e) => ErrorDataReceived(sender, e, errorData));
    process.OutputDataReceived += new DataReceivedEventHandler((sender, e) => OutputDataReceived(sender, e, outputData));

    if (exited != null) {
        process.EnableRaisingEvents = true;
        process.Exited += exited;
    }

    process.Start();
    process.BeginErrorReadLine();
    process.BeginOutputReadLine();
} 

Is there another way to force the window hidden or do I just have to use them they way they are? I've done a bunch of searching but all the answer I find just use some variation of the code above.

JHJ
  • 303
  • 1
  • 6
  • Can you attach screenshot? – Oleg Sep 23 '19 at 18:35
  • Also please try https://social.msdn.microsoft.com/Forums/vstudio/en-US/88c3b9f2-4573-40d1-8c9d-4384a707cb09/how-to-hide-the-window-of-a-new-process?forum=csharpgeneral with showindow interop dllimport – Oleg Sep 23 '19 at 18:38
  • Will this solution help https://stackoverflow.com/questions/6857019/how-to-start-process-hidden/13269085 – Sisir Sep 23 '19 at 18:52
  • And `WindowStyle = ProcessWindowStyle.Hidden` can be removed, as it requires `UseShellExecute` to be [true](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processwindowstyle?view=netframework-4.8) – LeBoucher Sep 23 '19 at 19:05
  • I added the screenshot. using ShowWindow(process.MainWindowHandle, SW_HIDE) sort of works. You need to call it after a delay so the window will show then be hidden (unless you call it too soon). The program above opens one window on startup then closes it and opens another. If the program opens another window that one will not be hidden. – JHJ Sep 23 '19 at 19:09

0 Answers0