1.

Solve : Help with REG QUERY to variable?

Answer»

Hello, guys.
I did a search but I couldn't solve my problem.

What I want to do is to retrieve a path from a registry key. Something like this:

Code: [Select]FOR /f "tokens=3" %%i in (
'reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" /v "Inno Setup: App Path"'
) DO (
SET InnoSetupPath=%%i
)

"%InnoSetupPath%iscc.exe" /Q /O"\..\bin\Release" "\..\Build\Installer\installer.iss"

I cannot get it to work.

Thanks everyone in advance.

EDIT: It must be something with spaces. Because "Inno Setup: App Path" returns for example "C:\Program Files\Inno Setup 5". I could user instead of "Inno Setup: App Path" "InstallLocation" but if the path returned has spaces the I cannot get the whole path. I get "C:\Program".
As a test batch I use the following:

Code: [Select]@ECHO ON
FOR /F "tokens=3" %%A IN ('REG QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\KLiteCodecPack_is1" /v "InstallLocation"') DO ECHO %%A
pausesomeone please? You declare 3 tokens, yet you only use the first token of three. (%%i) What do %%j and %%k contain?

Anyhow, try this:

Use simply delims==

for /f "delims==" %%i in ...

then %%i should contain the whole path including spaces

By the way, bumping is considered bad manners on this forum.


Quote from: Dias DE verano on February 25, 2009, 12:37:38 PM

You declare 3 tokens, yet you only use the first token of three. (%%i) What do %%j and %%k contain?

Anyhow, try this:

Use simply delims==

for /f "delims==" %%i in ...

then %%i should contain the whole path including spaces

By the way, bumping is considered bad manners on this forum.



Sorry for bumping, I thought that no one had seen the topic.

If you run REG QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" /V "Inno Setup: App Path" you will get:

Code: [Select]HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setu
p 5_is1
Inno Setup: App Path REG_SZ C:\Program Files\Inno Setup 5
I just want to use the install path of Inno Setup and set it as a variable in order to use it later.

Thanks for your patience and help!1. You know that the reg query output will be like this

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1
Inno Setup: App Path REG_SZ C:\Program Files\Inno Setup 5


2. You know:

a. You want the second line of the output.
b. The second line will be in an expected format
c. The second line has 5 space-delimited tokens before the text that you want.

assuming: "tokens=1-5* delims= "

Inno Setup: App Path REG_SZ C:\Program Files\Inno Setup 5
1 2 3 4 5 *
%%a %%b %%c %%d %%e %%f


3. Use FIND to isolate the 2nd line which CONTAINS "App Path"
4. Use "tokens=1-5* delims= " to put the path into the 6th token (asterisk means EVERYTHING after the 5th token)

So try this...

set RegCommand=reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" /v "Inno Setup: App Path"
FOR /f "tokens=1-5* delims= " %%a in ( ' %RegCommand% ^| find "App Path" ' ) do set InnoSetupPath=%%f

Thank you for your detailed explanation. I think I got it one and for all.
But, in XP it doesn't work.

Code: [Select]reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" /v "Inno Setup: App Path"

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setu
p 5_is1
Inno Setup: App Path REG_SZ C:\Program Files\Inno Setup\Inno Setup 5
It sets InnoSetupPath=Setup\Inno Setup 5.

So I deleted the delims= and it works in Vista and in XP. I don't know if it's COMPLETELY right what I did though.

Again, thank you very much for your help!Quote from: Chem4 on February 26, 2009, 03:39:54 PM
I deleted the delims= and it works in Vista and in XP. I don't know if it's completely right what I did though.

If it works, it must be. I was guessing about the delims, as I do not have Inno Setup on my PC.


Discussion

No Comment Found