2 Replies Latest reply on Jan 21, 2009 11:20 AM by nblinstrub

    Package Builder - using If search(registry...

    Rookie

      I need to query under a registry key for a hostname from among 20 hosts, then replace the hostname with a new host from a list of 20 replacements based on what host is found.

       

      I am working on a software distribution package that uses "If search(registry..." for each of the 20 original hostnames. Within the "If" statement is a "BEGINREGISTRY" statement querying the key, then replacing to hostname-based values.

       

      I'm using the first option for "If search(registry," "Read data value a specific registry value by key and value name." The statements look like this:

       

      IF SEARCH(Registry, "HKEY_LOCAL_MACHINE\SOFTWARE\Vendor\Application", "Host1", "$APPHOST1$")
      BEGINREGISTRY
      KEY: query, "HKEY_LOCAL_MACHINE\SOFTWARE\Vendor\Application"
      VALUE: reg_sz, replace, "NetworkDir", "\\newhost01\appdata"
      VALUE: reg_sz, replace, "RemoteHost", "newhost01"
      ENDREGISTRY
      ENDIF

       

      There are 20 of these searches for hosts 1-20. The search is not working and I'm lost at this point. Can someone give me a hint at what I need to change (option for the search, structure of my commands, etc.). It seems this is the way to go for my package so I'm anxious to get some answers.

        • 1. Re: Package Builder - using If search(registry...
          Employee

          The way I read your IF statement is like this: if a value named Host1 exists in HKLM\Software\Vendor\Application, then replace 2 other values in the same key.

           

          I don't have sufficient understanding of what you are trying to do to be sure that this is what you had in mind. Anyway, when I try the same IF statement in a little test, it seems to work right. I created a key called HKLM\Software\JB\Test, in which I created a value with name = "Host1" and data = "xyz". Then I tried this IF statement:

           

          IF SEARCH(Registry, "HKEY_LOCAL_MACHINE\SOFTWARE\JB\Test", "Host1", "AppHost1")

          ASK1: Yesno, text="True, the value of Host1 is $AppHost1$"
          ELSE
          ASK1: Yesno, text="False"
          ENDIF

           

          When I ran this, the IF evaluated True and I got a MessageBox that said "True, the value of Host1 is xyz". If the key (HKLM\Software\JB\Test) or value name aren't found, the IF evaluates false.

           

          You may notice a little difference between your syntax and mine: you have "$AppHost1$", I have "AppHost1". I've tried both, they both work the same.

          • 2. Re: Package Builder - using If search(registry...
            Rookie

            Jan,

             

            Thanks for the clarification on using the option I had chosen - I just had selected the wrong one. This morning I found I just had to select the third option, "Search registry for a value with matching data, starting at key. Search string can begin and/or end with a wildcard "*".

             

            IF SEARCH(Registry Recurse ByData, "HKEY_LOCAL_MACHINE\SOFTWARE\Vendor\Application", "host1", "", "RemoteHost")
            BEGINREGISTRY
            KEY: query, "HKEY_LOCAL_MACHINE\SOFTWARE\Vendor\Application"
            VALUE: reg_sz, replace, "NetworkDir", "\\newhost1\appdata"
            VALUE: reg_sz, replace, "RemoteHost", "newhost1"
            ENDREGISTRY
            ENDIF

             

            I had a section for each of my 20 original hosts and the package was able to locate and replace each of them. Hope I can remember this for next time!