'How can I write my for loop and reg query to return data containing spaces?

When I run the following in a batch file:

for /F "tokens=3" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 3990" /v "InstallLocation" 2^>nul') DO (SET INSTALL_LOCATION=%%A)

The value of INSTALL_LOCATION is C:\Program, rather than an expected value of C:\Program Files (x86)\Steam\steamapps\common\Sid Meier's Civilization IV Warlords.

I think this is a problem with my for loop as opposed to reg query, and also I suspect it is caused by the data for that key containing spaces.

How can I get the expected value, please?

My OS is Windows 11 and the script is being executed in CMD.

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source