views:

274

answers:

3

I'm using CreateProcess to exec Notepad.exe, but the process parent of notepad is my own AP. When I closed my own AP, the process parent of notepad became to explorer. How would I do to put explorer as process parent for this new opened process?

A: 

There is no built in way to set explorer.exe as the parent process right away. However, from what I can tell you can use p/invoke to make some calls to accomplish this.

Here is an article about the implementation using p/invoke to start as another user. THis gets you the intro to the p/invoke process. Then here is an article that talks about launching a non-child process. You can combine the information from the two to accomplish your desired goal.

Mitchel Sellers
+3  A: 

This question makes no sense. Windows does not have a real parent child relationship between processes in the way other OS's might. Incidentally, some in formation about the launching process is kept, but, outside of the CreateProcess launch code, that duplicates handles and the environment from the parent process, there is no further special relationship between the processes. They run, completely independently, as peers.

Some taskmanagers do show a heirachical relationship implying that parent child relationships persist, but ultimately thats just derived by scanning the list of processes creation info to see if matches can be found that imply other processes were their creator - and hence parent.

Chris Becke
A: 

Try using CreateRemoteThread() to create a new thread inside the address space of explorer.exe (if it is running), and then have that thread launch Notepad.

Remy Lebeau - TeamB
CreateRemoteThread is a surefire way to have bad things happen to your customers/users. It is *very* hard to get right.
Paul Betts
2 Paul: creating remote thread is the right answer. Any technique of code injection (e.g. hooks) would be a correct reply for this kind of question. Let's not blame correct answers, let's blame "wrong" and "hackey" questions
Andrey