I am struggling to understand the values and variables properties of foreach.

Can someone please explain what exactly they do in the following example from the users guide?

I understand that the variable installedApplications comes from the registry read, but what about "key value name"? How is that set?

thanks!

<registryfind>
      <findall>1</findall>
      <keypattern>*</keypattern>
      <namepattern>DisplayName</namepattern>
      <rootkey>HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall</rootkey>
      <searchdepth>1</searchdepth>
      <variable>installedApplications</variable>
    </registryfind>
    <setinstallervariable>
      <name>text</name>
      <value></value>
    </setinstallervariable>
    <foreach>
      <values>${installedApplications}</values>
      <variables>key name value</variables>
      <actionlist>
        <registryget>
          <key>${key}</key>
          <name>Publisher</name>
          <variable>publisher</variable>
        </registryget>
        <actiongroup>
          <actionlist>
            <md5 text="${key}" variable="md5"/>
            <setinstallervariable>
              <name>text</name>
              <value>${text}
${md5}=${value}</value>
            </setinstallervariable>
          </actionlist>
          <rulelist>
            <comparetext>
              <logic>equals</logic>
              <text>${publisher}</text>
              <value>${project.vendor}</value>
            </comparetext>
          </rulelist>
        </actiongroup>
      </actionlist>
    </foreach>

asked 20 Mar '12, 13:05

wildcatz's gravatar image

wildcatz
16141417
accept rate: 0%

Was my answer and/or Python example confusing? If so, I could clarify further.

(23 Mar '12, 14:30) DevHopeful_2012

I believe the foreach in the example works with a list of lists because the return value of registryFind is a list and findall is set to true. Therefore, the foreach will iterate over the list, ${installedApplications}, but each element in the list is a list, itself. The example cleverly parses the list element by specifying a variable for each index. Something similar to the following:

installedApps = [('Notepad++', 'DisplayName', 'Notepad++'), ('Office14.STANDARD', 'DisplayName', 'Microsoft Office Standard 2010')]
for (key, name, value) in installedApps:
    print "Found Registry Entry:\\n\\tkey: %s\\n\\tname: %s\\n\\tvalue: %s" % (key, name, value)

Found Registry Entry:
    key: Notepad++
    name: DisplayName
    value: Notepad++
Found Registry Entry:
    key: Office14.STANDARD
    name: DisplayName
    value: Microsoft Office Standard 2010
link

answered 21 Mar '12, 01:35

DevHopeful_2012's gravatar image

DevHopeful_2012
176131521
accept rate: 9%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×8

Asked: 20 Mar '12, 13:05

Seen: 1,489 times

Last updated: 23 Mar '12, 14:30