Jump to content

Prompt string cannot resolve %username%


Recommended Posts

Guest ssg31415926
Posted

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?

  • Replies 6
  • Created
  • Last Reply

Popular Days

Guest ssg31415926
Posted

Re: Prompt string cannot resolve %username%

 

On 17 Mar, 15:02, ssg31415926 <newsjunkm...@gmail.com> wrote:

> 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?

 

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?

Guest Pegasus \(MVP\)
Posted

Re: Prompt string cannot resolve %username%

 

 

"ssg31415926" <newsjunkmail@gmail.com> wrote in message

news:7aa7592e-c88b-4805-825b-a70ff49497e2@d4g2000prg.googlegroups.com...

> 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?

>

 

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

Guest ssg31415926
Posted

Re: Prompt string cannot resolve %username%

 

On 17 Mar, 15:13, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:

> "ssg31415926" <newsjunkm...@gmail.com> wrote in message

>

> news:7aa7592e-c88b-4805-825b-a70ff49497e2@d4g2000prg.googlegroups.com...

>

> > 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?

>

> 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

 

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.

Guest Pegasus \(MVP\)
Posted

Re: Prompt string cannot resolve %username%

 

 

"ssg31415926" <newsjunkmail@gmail.com> wrote in message

news:7c283094-6570-439c-ad91-5521037457f4@u10g2000prn.googlegroups.com...

> On 17 Mar, 15:13, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:

>> "ssg31415926" <newsjunkm...@gmail.com> wrote in message

>>

>> news:7aa7592e-c88b-4805-825b-a70ff49497e2@d4g2000prg.googlegroups.com...

>>

>> > 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?

>>

>> 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

>

> 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.

 

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.

Guest ssg31415926
Posted

Re: Prompt string cannot resolve %username%

 

On 17 Mar, 16:24, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:

> "ssg31415926" <newsjunkm...@gmail.com> wrote in message

>

> news:7c283094-6570-439c-ad91-5521037457f4@u10g2000prn.googlegroups.com...

>

>

>

> > On 17 Mar, 15:13, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:

> >> "ssg31415926" <newsjunkm...@gmail.com> wrote in message

>

> >>news:7aa7592e-c88b-4805-825b-a70ff49497e2@d4g2000prg.googlegroups.com...

>

> >> > 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?

>

> >> 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

>

> > 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.

>

> 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.

 

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.

Guest Pegasus \(MVP\)
Posted

Re: Prompt string cannot resolve %username%

 

 

"ssg31415926" <newsjunkmail@gmail.com> wrote in message

news:b3aa7f7b-a41d-4313-bfc2-ce086ae8923d@s8g2000prg.googlegroups.com...

> On 17 Mar, 16:24, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:

>> "ssg31415926" <newsjunkm...@gmail.com> wrote in message

>>

>> news:7c283094-6570-439c-ad91-5521037457f4@u10g2000prn.googlegroups.com...

>>

>>

>>

>> > On 17 Mar, 15:13, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:

>> >> "ssg31415926" <newsjunkm...@gmail.com> wrote in message

>>

>> >>news:7aa7592e-c88b-4805-825b-a70ff49497e2@d4g2000prg.googlegroups.com...

>>

>> >> > 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?

>>

>> >> 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

>>

>> > 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.

>>

>> 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.

>

> 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.

 

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%.


×
×
  • Create New...