I’m getting a value from the registry which has this string of data: %USERPROFILE%\Desktop
If i manually put cd %USERPROFILE%\Desktop it’d correctly perform cd C:\Users\Name\Desktop
But when i read the data from the registry, it gives set DESKTOP = %%USERPROFILE%%\Desktop
So if i do cd %DESKTOP% (cd %%USERPROFILE%%\Desktop) it performs cd %USERPROFILE%\Desktop
Which gives the error: The system cannot find the path specified.
How can i resolve/evaluate the %%USERPROFILE%%\Desktop string data? (so %%USERPROFILE%% becomes C:\Users\Name)
Also this is how i get the data from the registry:
for /f "tokens=2*" %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop') do set DESKTOP=%%b
>Solution :
You need the CALL command to evaluate an expression a second time.
echo %desktop%
call echo %desktop%
The CALL also works with other commands like SET, but not in front of IF or FOR