2

i have a problem in a string with variable included
I read a key in registry like this :

call:ReadReg "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" "Desktop"
echo %RegValue%

:ReadReg
FOR /F "usebackq tokens=1-3" %%A IN (`REG QUERY "%~1" /v "%~2" 2^>nul`) DO (
    set RegName=%%A
    set RegType=%%B
    set RegValue=%%C
)
goto:eof

but the value returned in RegValue is: %USERPROFILE%\Desktop instead of : C:\Documents and Settings\username\Desktop

the ECHO line display :

C:\Documents and Settings\alopez>echo %USERPROFILE%\Bureau
%USERPROFILE%\Bureau

I would like convert the registry value into a good path

1

1 Answer 1

4

Replace set RegValue=%%C with call set RegValue=%%C This will cause variable expansion twice; once for the call command and then again for the set command. Run this example .bat script to see it in action.

@echo off

set x=%%Path%%
echo %x%
echo.
call echo %x%
call set x=%x%
echo.
echo %x%
pause >nul
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.