System Expandable-String Environment Variables Can’t Reference User Environment Variables

Posted by Synetech inc. on Super User See other posts from Super User or by Synetech inc.
Published on 2010-04-11T22:31:59Z Indexed on 2010/04/11 22:33 UTC
Read the original article Hit count: 1232

Hi,

I’ve run into a bit of a situation with Windows environment variables. I’ve narrowed it down to what may or may not makes sense and/or possibly be by design. It seems that expandable-string environment variables of the local machine cannot reference environment variables of the current user.

For example if you’ve got the following environment variables:

[HKCU\Environment]
"CU"="CU"
"CU->LM"="%LM%"

[HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"LM"="LM"
"LM->CU"="%CU%"

Then you get the following results:

> set CU
CU=CU
CU->LM=LM

> set LM
LM=LM
LM->CU=%CU%

It seems that user variables can expand system variable references, but system variables cannot expand (access?) user variable references.

I suppose that it makes sense if you think about it just right (eg like how user vars override/hide system vars of the same name), but it also doesn’t make sense if you think about it in even more ways.

So what’s going on? Is there a way to get this to work as expected?

Thanks.

© Super User or respective owner

Related posts about Windows

Related posts about environment-variables