How can I view a Windows environment variable without running arguments in it?

Basically, I would like to automatically export my exact PATH variable to a file. It contains things like %ANT_HOME%/bin , and I would like to save it that way. From what I could find, using set and echo will execute this argument and give me an absolute path. Is something missing?

+4
source share
3 answers

To get a copy of your PATH without expanding the environment variables, you can save the following as "rawPath.vbs" ...

 Option Explicit Dim wsh Set wsh = CreateObject("Wscript.Shell") Wscript.Echo wsh.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path") 

... and then issue the following command to output the output to a file

 cscript -nologo rawPath.vbs > myPath.txt 
+5
source

Do you see %ANT_HOME% when executing SET from the prompt?

If yes,

 >filename echo %path% 

should export the path as desired.

If the PATH variable does not actually contain the characters "%", it has already been resolved. And remember that “%” is actually a legitimate (but annoying) file name ...

You can set the symbol "%" to the environment variable

 set var=%%something%% 

set var to %something%

+1
source

You need to escape from % good sir, example

 >echo %path% C:\windows\system32;C:\windows\system32\wbem >echo ^%path^% %path% 
0
source

All Articles