Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help with REG QUERY to variable  (Read 22554 times)

0 Members and 1 Guest are viewing this topic.

Chem4

    Topic Starter


    Rookie

    • Experience: Familiar
    • OS: Windows 7
    Help with REG QUERY to variable
    « on: February 24, 2009, 08:02:25 PM »
    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
    pause
    « Last Edit: February 25, 2009, 07:24:46 AM by Chem4 »

    Chem4

      Topic Starter


      Rookie

      • Experience: Familiar
      • OS: Windows 7
      Re: Help with REG QUERY to variable
      « Reply #1 on: February 25, 2009, 11:25:45 AM »
      someone please? :)

      Dias de verano

      • Guest
      Re: Help with REG QUERY to variable
      « Reply #2 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.


      « Last Edit: February 25, 2009, 01:05:21 PM by Dias de verano »

      Chem4

        Topic Starter


        Rookie

        • Experience: Familiar
        • OS: Windows 7
        Re: Help with REG QUERY to variable
        « Reply #3 on: February 25, 2009, 03:29:02 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!
        « Last Edit: February 25, 2009, 03:56:19 PM by Chem4 »

        Dias de verano

        • Guest
        Re: Help with REG QUERY to variable
        « Reply #4 on: February 26, 2009, 11:46:42 AM »
        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


        Chem4

          Topic Starter


          Rookie

          • Experience: Familiar
          • OS: Windows 7
          Re: Help with REG QUERY to variable
          « Reply #5 on: February 26, 2009, 03:39:54 PM »
          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!

          Dias de verano

          • Guest
          Re: Help with REG QUERY to variable
          « Reply #6 on: February 26, 2009, 03:45:41 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.