LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Not a refnum not working oregistry

Solved!
Go to solution

I need to check if a registry key exist:

 

michelesantucci_0-1730993869842.png

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

 

0 Kudos
Message 1 of 6
(341 Views)

@michele.santucci wrote:

 

 

How can I check for registry key existence?

 

 


Obviously try to read your key and check Error Out instead of refnum.

Message 2 of 6
(332 Views)

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.

Rolf Kalbermatter
My Blog
Message 3 of 6
(319 Views)

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:

michelesantucci_0-1731064844996.png

Trapping -603 error code should work.

0 Kudos
Message 4 of 6
(279 Views)
Solution
Accepted by topic author michele.santucci

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:

 

rolfk_2-1731068323773.png

 

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!

Rolf Kalbermatter
My Blog
Message 5 of 6
(267 Views)

Oh thnx! I never tought to use the case sequence this way... but it's just what I needed.

0 Kudos
Message 6 of 6
(254 Views)