简体   繁体   中英

How do I prevent “end process tree” from terminating the programs mine has started?

I am trying to execute an EXE 'two.exe' from another application 'one.exe' in Delphi XE2 using ShellExecute.

ShellExecute(0, 'open', 'two.exe', nil, nil, SW_NORMAL);

It works perfectly, but whenever I terminate application 'one.exe' (the parent app) from Task Manager's process tab, using the "end process tree" option, the application 'two.exe' also gets terminated.

How can I prevent my ShellExecuted application from getting terminated like this?

Ok, not very nice solution... but tested with success ;o)

ShellExecute(0, 'open', 'cmd', 
  PChar('/C  start "" "' + Application.ExeName + '"'), nil, SW_HIDE);

在此输入图像描述

The first is manually launched... his child with regular shellexecute call... The last one, with the shellexecute + cmd trick...

/C explanation

I think you need to create an intermediate process which in turn spawns two.exe . You then need the intermediate process to terminate immediately, at which point the relationship between the original process and two.exe is broken.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM