11-07-2024 09:42 AM
I need to check if a registry key exist:
Unluckly not-a-number/path/refnum does not work on registry refnums ... it always returns FALSE regardless of whether the registry exists or not.
How can I check for registry key existence?
Best regards,
Mike
Solved! Go to Solution.
11-07-2024 09:59 AM
@michele.santucci wrote:
How can I check for registry key existence?
Obviously try to read your key and check Error Out instead of refnum.
11-07-2024 10:23 AM
The registry key refnum is not a real refnum (well it actually is a queue refnum, but casted into a datalog refnum to hide the internal implementation and not let a user manipulate the content in the queue). The Is Not a Refnum node sees that the refnum is a datalog refnum and then queries the datalog cookie jar for validity and that cookie jar tells the function, no this is not a refnum that I ever have seen.
What usually works but isn't quite foolproof, is a comparison to be unequal to the Not a Refnum constant. The only foolproof way is to try to access the registry refnum, for instance by calling Query Registry Key Info.vi. If that returns an error -600, you got almost certainly an invalid refnum.
11-08-2024 05:22 AM
Is it possible to use a Query Registry Key Info.vi on a non existent registry key?
Why not simply use Open Registry Key.vi ?
I did this:
Trapping -603 error code should work.
11-08-2024 06:27 AM
Ohhh I see you try to solve a different problem than what the subject title of your post indicates. I was wrongly assuming that you were tripping over the fact that Not A Refnum? doesn't work on a registry refnum since it always will claim that the registry refnum is not a valid (datalog) refnum. It isn't, since it really is a queue refnum underneath.
You just want to see if the opening of the registry key was successful and that is of course best done by observing the error out of the Open Registry Key function. I usually work like this:
This way you know for sure that the error out of the open function indicates that the function failed and is not caused by something further upstream. This allows you to react on the error from this function without having to check that the error number is equal to a certain value. Basically if the Open Registry Key function failed, no matter how, there is no way that you could do anything with that invalid registry refnum.
The strange wrinkle around the Close function is because unlike most other Close functions in LabVIEW, the registry Close (at least until LabVIEW 2020) will actually do nothing when the error in indicates an error. A clear design flaw of this library. Pretty much all other Close functions in LabVIEW will attempt to at least close the resource, independent of any incoming error, and only return an error from that close attempt if the incoming error in indicated no error!
But in earlier LabVIEW versions (<= 8.6) it was even worse. The Close function only closed the internal queue refnum but didn't close the two associated Windows registry handles!
11-08-2024 06:59 AM
Oh thnx! I never tought to use the case sequence this way... but it's just what I needed.