0

I'm trying to start a process using the following code :

Process.Start(new ProcessStartInfo()
        {
            FileName = $"{Environment.CurrentDirectory}\\file.exe"
        });

The process starts as it should be. However, when I look at the task manager, I see this:

1.

Is there any way to start the process without attaching it to the current one?

Thanks in advance, Lior.

Lior v
  • 464
  • 3
  • 12
  • The marked duplicate has some answers, but I suspect this isn't the best solution to the problem you're trying to solve. – Gabriel Luci Jan 20 '22 at 18:41
  • It looks exactly what I did, maybe it is different in VB. @GabrielLuci – Lior v Jan 20 '22 at 18:49
  • What is exactly what you did and how was the result different? But I think the better question is still why do you want this? – Gabriel Luci Jan 20 '22 at 18:52
  • What I did is the code above, It is very similar to the marked solution in the other question (which is written in VB).As to why I want this, I need the child process to stay alive after killing the parent. – Lior v Jan 20 '22 at 18:56
  • That makes sense. Use this answer then: https://stackoverflow.com/a/64300073/1202807 – Gabriel Luci Jan 20 '22 at 18:57
  • I have already tried this, it doesn't work either. – Lior v Jan 20 '22 at 19:00
  • When you say "after killing the parent", how are you killing the parent? Is the program just exiting normally, or are you using "Kill process tree"? – Gabriel Luci Jan 20 '22 at 19:09
  • I need the child process to stay alive either when killing the parent by `Environment.Exit(0);` or when just killing the process tree manually from task manager. – Lior v Jan 20 '22 at 19:12
  • Well if you kill the process tree, then you'll be killing all child processes. So just don't do that. But setting `UseShellExecute = true` will let the child processes continue after the parent exits normally, or if the parent (and not its process tree) is killed. – Gabriel Luci Jan 20 '22 at 19:15
  • The child is killed as well when I use this [solution](https://stackoverflow.com/a/64300073/1202807) (which uses `UseShellExecute = true` and `Environment.Exit(0)`) – Lior v Jan 20 '22 at 19:17
  • I've tested this myself and I can't reproduce what you're seeing. – Gabriel Luci Jan 20 '22 at 19:30
  • Success! I created a batch file which contains the command to start the process, Started it as a process and then killed it (In the window loaded event so it has enough time to start to process I want). – Lior v Jan 20 '22 at 20:23
  • Can you reopen the question, so I can post the answer? @GabrielLuci – Lior v Jan 20 '22 at 20:24
  • That's basically the same as this answer: https://stackoverflow.com/a/8434682/1202807 – Gabriel Luci Jan 20 '22 at 22:49

0 Answers0