PDA

View Full Version : Reading the Registry



AutoPlayUser
10-10-2011, 03:57 AM
Hi,

I have a problem with my old code snippet, where I try to figure out
all installed versions of a certain software. Each version is listed in the registry
as an own key, e.g.

\\SOFTWARE\\Company\\Company_Software\\1.0
\\SOFTWARE\\Company\\Company_Software\\1.1
\\SOFTWARE\\Company\\Company_Software\\2.0
\\SOFTWARE\\Company\\Company_Software\\3.0

Each of these keys contains the entry "Path", containing
the absolute path of the installation.

So what I try is to read out those Paths and output them into
a selection box, so that the user can choose the correct
path for the running setup.




-- 32 BIT REGISTRY
-- Check if there is a software already installed
subKey = "\\SOFTWARE\\Company\\Company_Software\\";


if (Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, subKey)) then
-- get all version keys
versNames = Registry.GetKeyNames(HKEY_LOCAL_MACHINE, subKey);
Table.Sort(versNames, nil)

Dialog.Message("TEST", subKey, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON2);

for x,y in versNames do

-- create new subKey with version number
versionKey = String.Concat(String.Concat(subKey, "\\"), y);

-- read the path
regPath = Registry.GetValue(HKEY_LOCAL_MACHINE, versionKey, "Path", false);



if (regPath == "") then
else
-- put path into list box
DlgListBox.AddItem(CTRL_LIST_BOX, regPath);
end

end

else
-- No REG KEYs found, keep continueing with next dialog
Screen.Next();
end


The code has worked so far, but today, when running the setup I got the error:

On Preload, Line50: attempt to call table value.

Any ideas what is wrong with my code?

Bests,

AutoPlayUser
10-10-2011, 04:10 AM
Seems, that some former update changed the LUA behavior.
After replacing:
for x,y in pairs(versNames) do

it works....