Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
How to start a Start new process, without being a child of the spawning process 4 answers
I am using Process.start(). But in that case it is getting created as a child of the calling process.


What I have tried:

I am calling as Process.Start(fullPathtoexe)
Posted
Updated 26-Jul-16 4:48am
v2
Comments
Richard Deeming 26-Jul-16 10:18am    
Already has an answer where? You didn't provide a link.

And if it already has an answer, then what's wrong with that answer?
DSomesh 26-Jul-16 10:38am    
I googled and found that cmd can be used to launch a process and terminate as an intermediate process.
string x = "/c " + fullPath+".exe";
Process.Start(new ProcessStartInfo { Arguments = x, FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden });
But it did not work.

1 solution

When you start a process, you are the parent. If you want to remove that link, you need to spawn an intermediate process that spawns your target process and then terminates. Because the intermediate process is the parent of the target process, when it closes the child linkage is broken.

That's not difficult to do: just write a quick no-window app that accepts parameters that are the process to start and its parameters. It uses Process.Start and then terminates.

But I'm not sure why you want to do this...
 
Share this answer
 
Comments
DSomesh 26-Jul-16 10:34am    
I googled and found that cmd can be used to launch a process and terminate as an intermediate process.
string x = "/c " + fullPath+".exe";
Process.Start(new ProcessStartInfo { Arguments = x, FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden });
But it did not work.
OriginalGriff 26-Jul-16 10:48am    
"it did not work" is one of the most useless error reports you can give - it tells us nothing. We can guess that it doesn't work because otherwise you wouldn't be asking about it, but we have no idea in what way it "didn't work".
Remember that we can't see your screen, access your HDD, or read your mind - we only get what you type to work with.
So perhaps you want to explain what happened that you didn't expect, or didn't happen that you did...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900