the %cmdcmdline% approach winds up yielding the same 'shell execute' style path under the special context where a custom Windows filetype (cmd.exe ftype command) has been associated with an auto execute file extension (assoc + %PATHEXT%) (here's my own project demonstrating that kind setup, but it's not in scope to include all that code here)
what worked for us is a quickly built util "pids.exe" that provides the nested parent process names, and then using that to check for whether explorer.exe was present, for example:
for /f %%v in ('pids.exe -name -level 3') do if \"%%v\"==\"explorer.exe\" timeout /t 10
permalink to this usage in a demonstrable script
pids will dump a typical usage block when no args are provided and there are a few more flags that might come in handy in slightly different situations
i imagine there are other command line tools already out there doing this, i just couldn't find them with an admittedly light amount of searching