[Bug 12] The registry "exists" check failes on keys, only works for values

bugzilla-daemon at wpkg.org bugzilla-daemon at wpkg.org
Thu Dec 1 15:20:37 CET 2005


Please reply using this URL only: http://bugs.wpkg.org/show_bug.cgi?id=12





------- Additional Comments From kristofer.kiik at gmail.com  2005-12-01 15:20 -------
Oops, this did not work after all. I did some checking and came up with a new
function to check the existance of a registry key. 

It appears that if you do a regRead on a key that has no (default) value, then
you get the exact same error as if you tried to read a nonexistent key: error
nr. -2147024894. However the error message is different, so comparing those
helps. So the fixed function:
=====================================
function getRegistryValue(keyName) {
    var WshShell = new ActiveXObject("WScript.Shell");
    var val;
    try {
        val = WshShell.RegRead(keyName);
    } catch (e) {
        val = null;
    }

	if (val == null)
	{
			try
	{
	WshShell.RegRead("AnInvalidKey\\");
	}
	catch (e)
	{
		sDescription = e.description;
        sDescription = sDescription.replace("AnInvalidKey\\", "");
	}

	try {
        var regKey = WshShell.RegRead(keyName + "\\");
    } catch (e) {
		tDescription = e.description;
        tDescription = tDescription.replace(keyName + "\\", "");
		if (sDescription == tDescription)
		{
			val = null;
		} else {
			val = "<its a key!>";
		}
    }

	}

    return val;
}
==========================

-- 
Configure bugmail: http://bugs.wpkg.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the wpkg-users mailing list