|
-
Nov 3rd, 2011, 02:19 PM
#1
[RESOLVED] Registry Key Exists
I'm having a hard time determining if a registry exists or not. This is what I'm trying:
VB.NET Code:
Dim r4 As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full")
If Not r4 Is Nothing Then
If Not r4.GetValue("Version") Is Nothing Then
Return CStr(r4.GetValue("Version"))
Else
Return "4"
End If
End If
The registry key exists on my PC, so I'm having a hard time debugging it on another PC. When it threw the error, I commented out the last block of code to see if I was checking the key wrong or if it would throw the error just on the variable declaration.
Which is did. I get why it did. You can't .Open a key that doesn't exist. However, I looked it up and everyone is recommending that we do it this way. But this way doesn't exist.
Anyone have any ideas?
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Nov 3rd, 2011, 02:24 PM
#2
Re: Registry Key Exists
Delete the key on your PC [or at least change the name] and run the code and step through to see what actually happens. See if r4 actually is Nothing.
-
Nov 3rd, 2011, 02:33 PM
#3
Re: Registry Key Exists
 Originally Posted by formlesstree4
Delete the key on your PC [or at least change the name] and run the code and step through to see what actually happens. See if r4 actually is Nothing.
Thanks for the advice, formless.
It turns out I'm an idiot 
There's two methods I created and I forgot about the other. They have the same names except the suffix for each is different. One method returns a string, the other returns a boolean.
When I read the error log, I only read the first part and assumed it was this method. After changing the key name and seeing that the code never got to my break point, I realized it was the other method. The other method didn't have a check to determine if the key was nothing.
Everything's good now.
Thanks again.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|