0

The goal is to have a console application which is able to start a process without opening it in a new window.

This is the working code in .net 4.6, which I am testing by launching notepad.exe:

ProcessStartInfo startInfo = new ProcessStartInfo()
{
    WorkingDirectory = exeFileInfo.Directory.FullName,
    FileName = exeFileInfo.Name,
    Arguments = cmdStr,
    CreateNoWindow = true,
    UseShellExecute = true,
    WindowStyle = ProcessWindowStyle.Hidden
};

When translating it to dotnet core there are two issues with this same code:

  1. Compilation error: 'ProcessStartInfo' does not contain a definition for 'WindowStyle'
  2. Runtime exception: System.PlatformNotSupportedException: 'UseShellExecute must always be set to false.'.

Is there any way to execute a hidden process? (at least in Windows).

Xavier Peña
  • 7,399
  • 9
  • 57
  • 99
  • _(at least in Windows)_ - then use `4.6 NET Framework`. .NET Core was designed for running on different platforms. So all Windows dependencies was removed. `WindowStyle` is Windows related property. – Fabio Aug 03 '17 at 11:41
  • 1
    Note that [you aren't guaranteed](https://stackoverflow.com/a/5094079/21567) that this works (launching a non-Console process hidden), even with the full framework. (If you have the source for the process being started, provide it with a special command line option to make it hide itself.) – Christian.K Aug 03 '17 at 11:42
  • @Fabio The idea behind "at least in Windows" is to gain time before the feature is "correctly implemented" in dotnet core. If I go back to NET46 I will have to do more work later to port it to linux (if that was finally possible in the future). – Xavier Peña Aug 03 '17 at 11:53
  • @Christian.K I see: `CreateNoWindow only applies to console mode apps, it won't create the console window. // WindowStyle only applies to native Windows GUI apps. `. That means that my tests with `notepad.exe` won't work. Ideally I would like to hide "native windows gui apps", but being able to hide console applications might be enough for the moment. – Xavier Peña Aug 03 '17 at 11:56
  • 1
    Note that the `WindowStyle` property is just passed on to the target process, and it's up to it what to do with that. Notepad does honor it, but an arbitrary program may not, and you can't ultimately warrant it from your program, unless you also control the target program. – Alejandro Aug 03 '17 at 13:00

0 Answers0