I am trying to query the install location of a program in the registry. All I’m interested in is the location output.
This question has a partial solution, but it doesn’t quite help.
On Windows 7, the reg command outputs a stupid registry key header along with the value, as shown below:
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NSIS Unicode" /v InstallLocation
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NSIS Unicode
InstallLocation REG_EXPAND_SZ C:\Program Files\NSIS
First, is there a way to turn off the header and simplify the output?
At the command prompt, I can change the above to
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NSIS Unicode" /v InstallLocation | findstr InstallLocation
so that it returns me just the second line.
Now, if I am to use a FOR /F to parse this and get only the directory value, the FOR command fails saying | was unexpected at this time.
Here’s my batch file:
@for /f "tokens=2* delims= " %%k in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NSIS Unicode" /v InstallLocation | findstr InstallLocation') do @echo %%k
So where am I going wrong?
You must escape the
|character using a caret (^).this would return
REG_SZon my machine.