1

When trying to customize my command prompt I faced a strange behaviour:

from the CMD the line

SET set prompt=$D $T$H$H$H$_%USERNAME%@%COMPUTERNAME%$_$P$G

works as expected:

28/05/2020 12:02:15
DDS@DDS-PC
C:\Users\DDS>

But if I set the same variable EDIT: (in "variable for user DDS") with the very same values from the windows utility to set variables I got:

28/05/2020 12:04:18
SYSTEM@DDS-PC
C:\Users\DDS>

NOTE: the utility itself is showing the value correctly DDS when editing the variables, just the command prompt resolves %USERNAME% to SYSTEM

  • There are 2 kinds of environment variables, system and user ... – DavidPostill May 28 at 10:45
  • I inserted mine in "variables for user DDS" when using the tool (the upper form), hence I think It's a user variable in both cases – DDS May 28 at 10:47
  • winsourcecode.blogspot.com/2019/05/… is a small program to list your variables and where they come from. List System, User, Volatile, and the resultant Process environmental variables that programs use. System variables are set before logon. Therefore it can't be your user name. – Mark May 28 at 17:08
1

When you execute this from the system app, it is run under the SYSTEM user.

Keep in mind that the variables are not updated with every prompt. This means that if you were to change your username, your prompt does not. It becomes a static text. Given that you use prompt variables for the date, they get updated, but the computername and username are not.

I don't think this is going to be a massive problem, but you can do 2 things to resolve this. Either not use %USERNAME% but just write out your username (it doesn't matter anyway) or use the command prompt to set the prompt correctly, then push that to the system using:

setx PROMPT %PROMPT%

To test this, try using %CD% in your prompt, then change directory. Notice how your prompt still shows the old directory.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.