Prompt string cannot resolve %username%

Prompt string cannot resolve %username%

Post by ssg3141592 » Wed, 19 Mar 2008 00:02:42


I've set my prompt string to: $_Connected to:$S%computername%$Sas:$S
%username%$_$p$g using this registry key: HKEY_LOCAL_MACHINE\SYSTEM
\CurrentControlSet\Control\Session Manager\Environment and then logged
off and on again.

When I start cmd.exe, it displays as:

Connected to: TESTBOX1 as: %username%
C:\Documents and Settings\testuser1>

Does anyone know why %computername% resolves correctly but %username%
does not?
 
 
 

Prompt string cannot resolve %username%

Post by ssg3141592 » Wed, 19 Mar 2008 00:03:16


For info, the reason I'm doing this is to make things clearer when
using WinRS. If I use WinRS to connect to the same machine, using
this command:

WinRS -r:TESTBOX1 cmd

the prompt displays correctly:

Connected to: TESTBOX1 as: NETWORK SERVICE
C:\Documents and Settings\testuser1>

Why does it work when I connect remotely but not work when I run
cmd.exe locally?

 
 
 

Prompt string cannot resolve %username%

Post by MV » Wed, 19 Mar 2008 00:13:04


Works fine for me in local mode. Instead of hacking the
registry and logging off and on, try this command from a
Command Prompt:

prompt $_Connected to:$S%computername%$Sas:$S%username%$_$p$g
 
 
 

Prompt string cannot resolve %username%

Post by ssg3141592 » Wed, 19 Mar 2008 00:47:40


What happens if you log off and on after you've done that?

I can't do that as I want to include it in an SMS package. The reason
I'm doing this is to make things clearer when using WinRS, which I'm
about to deply. If I use WinRS to connect to the same machine, using
this command:

WinRS -r:TESTBOX1 cmd

the prompt displays correctly:

Connected to: TESTBOX1 as: NETWORK SERVICE
C:\Documents and Settings\testuser1>

So, I'm puzzled as to why it works when I connect remotely but doesn't
work when I run cmd.exe locally.
 
 
 

Prompt string cannot resolve %username%

Post by MV » Wed, 19 Mar 2008 01:24:18


The reason why I suggested the Command Prompt command
was that it would give you some valuable pointers. I urge you
to try it.

Instead of hacking the registry, I prefer to use standard commands
if available. I tested the following command in a local session:

setx.exe prompt "$_Connected to:$S%computername%$Sas:$S%username%$_$p$g" -m

It worked as expected. There is no need to log off/on to test it -
it affects all processes that are launched subsequently. Setx.exe
comes with the Windows Resource Kit.
 
 
 

Prompt string cannot resolve %username%

Post by ssg3141592 » Wed, 19 Mar 2008 02:56:20


Agreed re standard commands - . I've had a play with it, at your
prompting. The problem is that command sets the registry key to:
$_Connected to:$STESTBOX1$Sas:$Stestuser1$_$p$g. So, when a user
log's on remotely they get the same prompt string which won't be
correct if a different user is connecting.

What I've noticed is that environment variables earlier in the
alphabet than "Prompt" work when inserted directly into the registry
and env vars after "Prompt" don't. Odd.
 
 
 

Prompt string cannot resolve %username%

Post by MV » Wed, 19 Mar 2008 04:38:24

"ssg31415926" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...

There are two problems with your current approach:
- When you set HKLM\SYSTEM\Current...\Environment\Prompt
to $_Connected to:$S%computername%$Sas:$S%username%$_$p$g
then the two variables won't be resolved because the "Prompt"
value is a Reg_SZ value. You would need to turn it into a
Reg_Expand_SZ value.
- When you log on then the %prompt% variable gets processed
***before*** the value of %username% variable is known.
Hence you won't see it in your prompt.

The issue is easily resolved by creating a tailor-made
Command Prompt: Instead of invoking cmd.exe directly,
invoke it like so:
cmd.exe /f:on /k prompt $_Connected
to:$S%computername%$Sas:$S%username%$_$p$g

And if you need to discriminate between local and RDP
users, put the whole thing into a batch file and test for the
existence of %ClientName%.