Results 1 to 5 of 5

Thread: [RESOLVED] Registry.LocalMachine.OpenSubKey returns Nothing

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,794

    Resolved [RESOLVED] Registry.LocalMachine.OpenSubKey returns Nothing

    I have an old, and small application with ~250 lines of code. The .NET framework is 2.0. I want to upgrade to newest .NET framework. Since the app is so small, I thought I will create a new app with the same name, select latest framework, and copied & pasted the code from old app to new with .NET Framework 4.5

    The problem is that opening a registry key returns "Nothing"
    Code:
            Dim SoftwareKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
    
            Using rk As RegistryKey = Registry.LocalMachine.OpenSubKey(SoftwareKey)
    The exact same code runs fine in the old app with .NET Framework 2.0, but this returns "Nothing" in the new app with .NET Framework 4.5 selected.

    Why something so simple is not working?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,493

    Re: Registry.LocalMachine.OpenSubKey returns Nothing

    What about just taking a copy of the original app, and simply changing the Target Framework? I've done that before to upgrade components from older FW versions.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Registry.LocalMachine.OpenSubKey returns Nothing

    Wouldn't the S-1-5-18 bit after UserData be some kind of very specific ID for a user?

    Something's changed, it's just hard to see what. When you say the old and new apps are working, are they working on the same or on different machines?
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  4. #4
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Registry.LocalMachine.OpenSubKey returns Nothing

    Also: get to debugging. The registry is a decrepit old thing and ever since virtualization was introduced there are a lot of little things that can go wrong.

    Can you open "Installer"? What about "UserData"? What about "S-1-5-18"? What about "Products"? Trying them one at a time will likely reveal "yes" to some and "no" to others. That gives you some information. Or it'll be "no" to all. That's more information.

    The API returns "Nothing" when it thinks you tried to open something that's not there. So be meticulous. Stop asking for exactly the thing you want and start asking for things you're definitely certain are there. If those don't work, we know the problem's likely in how OpenSubkey() is being used.

    You've only showed us 2 lines. Are those the only relevant ones? Maybe not. Perhaps if we saw more code we could find some other cause. I'm assuming you verified the Nothing via debugger? If so, maybe these are the most relevant lines. Hard to tell.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,794

    Re: Registry.LocalMachine.OpenSubKey returns Nothing

    Quote Originally Posted by techgnome View Post
    What about just taking a copy of the original app, and simply changing the Target Framework? I've done that before to upgrade components from older FW versions.

    -tg
    I'm getting old, I cant figure out the simple things now

    Thanks!

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