You can use ProcMon to find out how this is done ...
To save you trouble, ProcExp is defined as the taskmgr.exe debugger in the Image File Execution Options in the registry. This means that ProcExp starts before taskmgr starts, regardless of how taskmgr was started. ProcExp can then easily close the task manager and show itself.
eran
source share