... You'll probably get a HWND for it, but NtUserGetWindowThread returns nothing yet.
You're working around it in get_desktop_process_id by returning GetCurrentProcessId() in case things failed, but that looks wrong imho, and instead you should probably try to make this work without having to guess the desktop process id.
I have been looking at the relevant code paths and experimenting with a few alternatives, and it seems that getting an invalid desktop HWND during process startup combined with the process path having the "c:\windows\system32\explorer.exe /desktop..." form, should be a reliable indicator of being in the desktop window process. What do you think?