View Full Version : Registry.DoesKeyExist problem
bwalker
03-12-2010, 08:18 AM
I seem to be having a problem with this registry action.
I have a line in my code as follows:
Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, LicenseMainKey)
This seems to be returning false, even though when I look in the registry, it does exist. The other part of this, is that just opening the registry with regedit seems to solve the problem.
Can anybody tell me if this is some sort of known issue with this registry action?
jassing
03-12-2010, 08:51 AM
what does LicenseMainKey evaluate to?
bwalker
03-12-2010, 09:19 AM
LicenseMainKey evaluatets to "SOFTWARE\\CompanyName\\ProductName\\2009\\Licensin g"
At first I thought it might be some sort of "permissions" issue, however if I take away the "DoesKeyExist" check, I can succesfully write to that key.
jassing
03-12-2010, 10:14 AM
I dunno weird one.
if it returns false, then you open up regedit and exit, and then it returns true... very weird.
bwalker
03-12-2010, 10:31 AM
Yup, weird pretty much describes it.
But it is a big problem for me.
If I bypass the "DoesKeyExist" check, and just write to it, it seems to write just fine, but I would much rather see if the key exists first, because that determines if the app is installed in the first place, and I do not want to do the write to the key if the app is not installed.
jassing
03-12-2010, 10:52 AM
I've never had that problem.
if you can write to it -- try reading the value to see if it's there. end result is you know it if it's there or not.
Ulrich
03-12-2010, 12:04 PM
Do you perform any error checking when you get false from Registry.DoesKeyExist()?
For example, what do you get when you execute this code:
res = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, LicenseMainKey);
if (res == false) then
error = Application.GetLastError();
SetupData.WriteToLogFile("Error\tError " .. error .. " (" .. _tblErrorMessages[error] .. ") when searching for registry key '" .. LicenseMainKey .. "'\r\n");
end
This could show the exact error code, and display that you are indeed looking where you think you are looking for the key.
Ulrich
bwalker
03-12-2010, 03:06 PM
When I run the following in my code:
res = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, LicenseMainKey);
if (res == false) then
error = Application.GetLastError();
SetupData.WriteToLogFile("Error\tError " .. error .. " (" .. _tblErrorMessages[error] .. ") when searching for registry key '" .. LicenseMainKey .. "'\r\n");
end
res returns false, even though the key is there.
GetLastError() returns 0 (sucess), so there does not appear to be an error in the call.
I just don't get why it would return false, when the key is there.
Ulrich
03-13-2010, 08:45 AM
Hello,
I suppose that something is not exactly like you are telling us. The best would be if you allow us to have a look at the actual code you are using, by posting the exported project, or a slimmed down version of it where the issue still can be reproduced. If you don't want to make the project available to the public, you can contact some individuals who offer help privately, like Josh. I assume that you don't have an active maintenance contract, or you probably would have already opened a support ticket for this issue in the customer portal.
Ulrich
bwalker
03-15-2010, 02:17 PM
I found the answer to my problem.
My problem was in how I created the variable "LicenseMainKey".
It seems like I had more backslash characters than I needed.
I am still baffled by the fact that running regedit made the system more tolerant to the extraneous backslashes, but at least I can move forward now.
Thanks for all your help.
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.