Thanks for your explanations. It seems that on my system (Windows 11) the HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\???\VirtualDesktops gets never filled with anything. I was trying several times, but no value ever showed up there.
Google pointed me finally to a PowerShell module, that can do the trick: Gallery. This module has a command Get-DesktopName that returns the name of the current desktop. Can easily be used with CMD.
The module is also on GitHub. Maybe a look at the code reveals how the dev retrieves the desired information (I’m not good at reading code)
Anyway, for the time being I have a working solution 🙂