csd214
03-21-2005, 10:23 AM
Several forum members have asked for this action by analogy with Registry.DoesKeyExist(). Even without this action it is not difficult to write a working code:
sValueData = Registry.GetValue(HKEY_CURRENT_USER, sMyRegKey, "AppDir", true);
if sValueData == "" then
-- what to do when the value does NOT exist
else
-- do something when value does exist
end
There is a disadvantage with this code; the setup log will have en "Error" entry. I do not want the end user to believe there is a malfunction in my setup.
To avoid the log error message, I have to add this test:
nTypeValue = Registry.GetValueType(nFolder, sKey, sValue);
if nTypeValue == 0 then
-- the value does NOT exist
else
-- OK, read the value
end
Sometimes I want the data from several values assigned to the same key. Another way to avoid the log error:
sRegAppDir = "?"; sRegUninDate = "0000-00-00"; -- init
sRegInstDate = "0000-00-00"; sRegVer = "?"; -- init
sIrpKey = SessionVar.Expand("Software\\%CompanyName%\\%ProductName%");
tValueNames = Registry.GetValueNames(HKEY_CURRENT_USER, sIrpKey);
for i, d in tValueNames do
if d == "AppDir" then
sRegAppDir = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, "AppDir", true);
elseif d == "Uninstalled" then
sRegUninDate = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, " Uninstalled ", true);
elseif d == "Installed" then
sRegInstDate = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, " Installed ", true);
elseif d == "Version" then
sRegVer = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, "Version", true);
end
end
Obviously the test for the existence of a value is a recurring operation. Today I decided to write a generic function and put it in a table like Lorne has taught us (AMS Examples (http://www.indigorose.com/forums/showthread.php?t=7780)).
To put functions into tables is a great feature. My collection is increasing!
If I use the table 'Registry', I can use my function this way:
bAppDirExist = Registry.DoesValueExist("HKCU", sRegKey, sValueName);
At last I come to my question:
Is it dangerous to use a table with the name 'Registry' because that is a group of internal actions in SUF70 (and other IR products)?
(If you are interested, you will find the function in the attached file.)
BTW, Moderator, could .lua be an permitted file extension for upload?
sValueData = Registry.GetValue(HKEY_CURRENT_USER, sMyRegKey, "AppDir", true);
if sValueData == "" then
-- what to do when the value does NOT exist
else
-- do something when value does exist
end
There is a disadvantage with this code; the setup log will have en "Error" entry. I do not want the end user to believe there is a malfunction in my setup.
To avoid the log error message, I have to add this test:
nTypeValue = Registry.GetValueType(nFolder, sKey, sValue);
if nTypeValue == 0 then
-- the value does NOT exist
else
-- OK, read the value
end
Sometimes I want the data from several values assigned to the same key. Another way to avoid the log error:
sRegAppDir = "?"; sRegUninDate = "0000-00-00"; -- init
sRegInstDate = "0000-00-00"; sRegVer = "?"; -- init
sIrpKey = SessionVar.Expand("Software\\%CompanyName%\\%ProductName%");
tValueNames = Registry.GetValueNames(HKEY_CURRENT_USER, sIrpKey);
for i, d in tValueNames do
if d == "AppDir" then
sRegAppDir = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, "AppDir", true);
elseif d == "Uninstalled" then
sRegUninDate = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, " Uninstalled ", true);
elseif d == "Installed" then
sRegInstDate = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, " Installed ", true);
elseif d == "Version" then
sRegVer = Registry.GetValue(HKEY_CURRENT_USER, sIrpKey, "Version", true);
end
end
Obviously the test for the existence of a value is a recurring operation. Today I decided to write a generic function and put it in a table like Lorne has taught us (AMS Examples (http://www.indigorose.com/forums/showthread.php?t=7780)).
To put functions into tables is a great feature. My collection is increasing!
If I use the table 'Registry', I can use my function this way:
bAppDirExist = Registry.DoesValueExist("HKCU", sRegKey, sValueName);
At last I come to my question:
Is it dangerous to use a table with the name 'Registry' because that is a group of internal actions in SUF70 (and other IR products)?
(If you are interested, you will find the function in the attached file.)
BTW, Moderator, could .lua be an permitted file extension for upload?