As far as I know, this is really impossible. Depending on how much you know about the user environment, there might be a workaround:
Command
qwinsta
will provide you with a list of sessions for the computer. During these sessions, one of them will be active, so if this program is used in an interactive session, it will mainly contain a “registered user”, as you described it (this is much more complicated, maybe many users are logged in but only one can be active, and I just hope that you know enough about the use cases of your program to use this). You can analyze the output and work with this username.
Of course, this is a dirty hack, and it assumes that during the execution of your task there is no chance that users will change.
In addition, I chose qwinsta.exe because it is a very simple approach that does not require API calls or anything else, I'm still not sure if CMD has sufficient parsing capabilities to get the necessary information for you.
source share