Jack Tripper
Had this question 12
Question
Jack Tripper asked on
| 41366 views

How to use %ProgramFiles% in the Path environment variable?

I'm trying to add a folder to the system's Path environment variable.

i want to add %ProgramFiles%\SysInternals

to the existing path variable:

C:\PROGRA~1\Borland\Delphi5\Projects\Bpl;C:\PROGRA~1\Borland\Delphi5\Bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

So i go into place where you edit it:

http://i44.tinypic.com/30nhx4w.jpg

And i add my variable to the path:

%ProgramFiles%\SysInternals;C:\PROGRA~1\Borland\Delphi5\Projects\Bpl;C:\PROGRA~1\Borland\Delphi5\Bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

Then opening a new command prompt window the environment variable is not replaced with it's actual value:

Path=%ProgramFiles%\SysInternals;C:\PROGRA~1\Borland\Delphi5\Projects\Bpl;C:\PROGRA~1\Borland\Delphi5\Bin;C:\Windows\system32;C:\Windows;C:\Windows\Sy
stem32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Se
rver\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Pro
gram Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Windows\System32\WindowsPowerShell\v1.0\
...
ProgramFiles=C:\Program Files

Which you can see in the following screenshot:

http://i44.tinypic.com/b3ndz4.jpg


How to make it work?

David_O - Support Engineer
Found this helpful 0
Answer
David_O - Support Engineer replied on

Reply


Thank you for using the Microsoft Vista Answers Forum!

Try adding the folder to the system path without the “%” sign. Instead of typing  %ProgramFiles%\SysInternals   type  C:\Program File\SysInternals

Please reply and let us know if your issue is resolved or if you will need further assistance


David O
Microsoft Answers Support Engineer
Visit our and let us know what you think.
David O
Microsoft Answers Support Engineer
Visit our and let us know what you think.
TwilightSpirit
Found this helpful 7
Most Helpful Reply
TwilightSpirit replied on

Reply

This is just an intelligent guess, but following some investigation I believe I've found the problem:

If the definition of an environment variable var1 contains another environment variable var2 and the name of var1 is alphabetically less than the name of var2 (i.e. strcmp(var1, var2) < 0), then var2 won't get expanded. This seems to be because when Windows first sets up the environment variables, they are created in alphabetical order, so var2 does not exist until after var1 has already been created (and so the expansion can't be done).

I believe this is a limitation in Windows. Really some sort of dependency check between the variables should be carried out so that they are created in the correct order. Fortunately, there is a workaround.

1) Enable 'delayed variable expansion' in the registry (see http://batcheero.blogspot.com/2007/06/how-to-enabledelayedexpansion.html)

2) Change the '%' signs around var2 to '!', e.g. "%var2%" becomes "!var2!"

I've done some limited testing on Windows 7 and this appears to fix the problem.

Jack - Support Engineer
Found this helpful 0
Jack - Support Engineer replied on

Hello Jack Tripper,

Thank you for posting in the Microsoft Answers Forum.  You need to include the drive letter in the path. Try this:

C:\ %PROGRAMFILES%\SysInternals

I hope this is helpful.

Thanks,

Jack


Jack
Microsoft Answers Support Engineer
Visit our Microsoft Answers Feedback Forum and let us know what you think.
Jack
Microsoft Answers Support Engineer
Visit our Microsoft Answers Feedback Forum and let us k
Jack Tripper
Found this helpful 0
Jack Tripper replied on

Reply

Doesn't work:

http://i42.tinypic.com/xfq3jk.png


The configured environement variable:

c:\%PROGRAMFILES%\SysInternals;
C:\PROGRA~1\Borland\Delphi5\Projects\Bpl;C:\PROGRA~1\Borland\Delphi5\Bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

The resulting environment variable

Path=c:\%PROGRAMFILES%\SysInternals;C:\PROGRA~1\Borland\Delphi5\Projects\Bpl;C:\PROGRA~1\Borland\Delphi5\Bin;C:\Windows\system32;C:\Windows;C:\Windows
\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL
 Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\
Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Windows\System32\WindowsPowerShell\v1.0\

David_O - Support Engineer
Found this helpful 0
Answer
David_O - Support Engineer replied on

Reply


Thank you for using the Microsoft Vista Answers Forum!

Try adding the folder to the system path without the “%” sign. Instead of typing  %ProgramFiles%\SysInternals   type  C:\Program File\SysInternals

Please reply and let us know if your issue is resolved or if you will need further assistance


David O
Microsoft Answers Support Engineer
Visit our and let us know what you think.
David O
Microsoft Answers Support Engineer
Visit our and let us know what you think.
Jack Tripper
Found this helpful 2
Jack Tripper replied on

Reply

Try adding the folder to the system path without the “%” sign. Instead of typing  %ProgramFiles%\SysInternals   type  C:\Program File\SysInternals

That's the workaround i'm using until i can get an answer to this question.

Well, except for the typo in "Program Files"

The problem, of course, with using "C:\Program Files" is that the path is then hard-coded to "C:\Program Files". Note the original question: "How to use %ProgramFiles% in the Path environment variable"
10ninox
Found this helpful 0
10ninox replied on
Well, it works for me. You may try using that in shell first. When you echo %path% it should not still be %xxx%, it will print the value of it.

http://i40.tinypic.com/fequfc.jpg
Jack Tripper
Found this helpful 0
Jack Tripper replied on

Reply

Well, it works for me.

i see your "works for me", and raise you "fails on":
 - Windows 2000 Server
 - Windows XP
 - Windows Small Business Server 2003 Premium
 - Windows Vista
 - Windows Server 2008 Standard
 - Windows 7

http://i40.tinypic.com/mmy906.jpg

Glad it's not my computer that's broken.

Jack Tripper
Found this helpful 0
Jack Tripper replied on

Reply

You used %appdata%.

Try it with %programfiles%.
Jochen Ruhland
Found this helpful 0
Jochen Ruhland replied on

Reply

PMFJI but it looks like you did not understand the problem.

You have a bunch of environment variables declared in the shell, among these you have:

 C:\Users\jochenr>set
CommonProgramFiles=C:\Program Files\Common Files

Path="%ProgramFiles%\PC Connectivity Solution\";"%CommonProgramFiles%\Microsoft
Shared\Windows Live";C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\
Windows\System32\WindowsPowerShell\v1.0\;%ProgramFiles%\tools;C:\Windows\SUA\\common\;C:\Windows\SUA\\usr\lib\;"C:\Users\jochenr\Program Files"

ProgramFiles=C:\Program Files

SUA_ROOT_WIN=C:\Windows\SUA\

SystemRoot=C:\Windows

If you now look how these Variables are defined in the registry:

C:\Users\jochenr>reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    Path    REG_EXPAND_SZ    "%ProgramFiles%\PC Connectivity Solution\";"%CommonProgramFiles%\Microsoft Shared\Windows Live";%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%ProgramFiles%\tools;%SUA_ROOT_WIN%\common\;%SUA_ROOT_WIN%\usr\lib\

you can see that the part

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;

corectly expands to

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\
Windows\System32\WindowsPowerShell\v1.0\;

and

%SUA_ROOT_WIN%\common\;%SUA_ROOT_WIN%\usr\lib\

expands to

C:\Windows\SUA\\common\;C:\Windows\SUA\\usr\lib\

while the other parts that include Envirnonment-Variables like

%ProgramFiles%\tools;

are not expanded.

Why is there a difference in the handling  of %SystemRoot% in comparison to the handling of %ProgramFiles%?

awcolley
Found this helpful 0
awcolley replied on

Reply

The same bug exists for SystemDirectory; that is, you cannot use %SystemDirectory% (which is defined in HKLM\SYSTEM\CurrentControlSet\Control\Windows as %SystemRoot%\system32) within PATH.

By "cannot use" I mean %SystemDirectory% will NOT be expanded when PATH is evaluated.

I'm not sure why David O did not simply come out and say:

%ProgramFiles% is one of the Microsoft standard environment variables that will not expand properly in the system environment variable Path; others include %SystemDirectory%, etc.

You may define your own REG_SZ system environment variable (for example, MyProgFiles, setting its Data to C:\Program Files) and use that within the Data for Path. It will be properly expanded when PATH is evaluated.

Note: this is true on WinXP. I have not checked this on Vista yet.

 

Jack Tripper
Found this helpful 0
Jack Tripper replied on

Reply

i don't know why i didn't think to use Process Monitor sooner, but

 

> tcpview

 

i can then watch cmd.exe trying frantically to find it:

 

C:\Users\Ian\tcpdump.*

C:\Program Files\Borland\Delphi5\Projects\Bpl\tcpdump.*

C:\Program Files\Borland\Delphi5\Bin\tcpdump.*

C:\Windows\System32\tcpdump.*

C:\Windows\System32\wbem\tcpdump.*

C:\Program Files\Microsoft SQL Server\80\Tools\Binn\tcpdump.*

C:\Program Files\Microsoft SQL Server\90\Tools\Binn\tcpdump.*

C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\tcpdump.*

C:\Program Files\Microsoft\Visual Studio 8\Common7\IDE\PrivateAssemblies\tcpdump.*

C:\Windows\System32\WindowsPowerShell\v1.0\tcpdump.*

C:\Users\Ian\%programfiles%\SysInternals\

 

And there it is. It does not support %programfiles%, at all.

Windows Vista

Previous Previous Page of 2 Next Next