Results 1 to 3 of 3

Thread: [RESOLVED] Registry Key Exists

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Resolved [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:
    1. Dim r4 As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full")
    2.  
    3. If Not r4 Is Nothing Then
    4.      If Not r4.GetValue("Version") Is Nothing Then
    5.           Return CStr(r4.GetValue("Version"))
    6.      Else
    7.           Return "4"
    8.      End If
    9. 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

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #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.

  3. #3

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Registry Key Exists

    Quote Originally Posted by formlesstree4 View Post
    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

    Quote 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
  •  



Click Here to Expand Forum to Full Width