Results 1 to 6 of 6

Thread: [Resolved] reading reg values

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    11

    Resolved [Resolved] reading reg values

    I'm attempting to write an application which reads all sub keys from

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\

    I am managing to retrieve all the subkey names fine, however when I want to retrieve a value from within this I get nothing.

    My code is as follows:
    Code:
    Dim regkey As RegistryKey
            regkey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall\", True)
            Dim key As String
            Dim test As String
            For Each key In regkey.GetSubKeyNames()
                test = CType(regkey.GetValue(key & "\InstallDate"), String)
                TextBox2.Text = TextBox2.Text & vbCrLf & key & " - '" & test & "'"
            Next
    I've only tried the CType bit as I read that you need to convert a registry value to string to be able to read it.

    A result is as follows

    CNXT_MODEM_HDAUDIO_VEN_14F1&DEV_2BFA&SUBSYS_14F100C3 - ''
    Combined Community Codec Pack_is1 - ''
    Connection Manager - ''
    DirectAnimation - ''
    DirectDrawEx - ''
    DXM_Runtime - ''

    some of these obviously dont have a value for InstallDate however I know for sure that the Combined Community Codec Pack_is1 has a value for this.

    Any help is gratefully appreciated.
    Last edited by peteoc; Feb 27th, 2007 at 08:34 AM. Reason: Resolved

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: reading reg values

    You can't get a value like that from the parent key. Once you have all the subkey names you have to open each one. Then you can get the InstallDate value from each of those keys. The easiest way would be like this:
    Code:
    Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
    Dim subkey As RegistryKey
    
    For Each subkeyName As String In key.GetSubKeyNames()
        subkey = key.OpenSubKey(subkeyName)
        TextBox1.AppendText(String.Format("Name: {0} - InstallDate:{1}{2}", _
                                          subkeyName, _
                                          subkey.GetValue("InstallDate"), _
                                          Environment.NewLine))
        subkey.Close()
    Next subkeyName
    
    key.Close()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    11

    Re: reading reg values

    cheers jmcilhinney saved me alot of time.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    11

    Re: [Resolved] reading reg values

    would this work with .net v1.1 as I've just found out that v2.0 will not be available on users machines and cannot be installed either.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [Resolved] reading reg values

    Yes, it's the same code for .NET 1.1. It's using the Microsoft.Win32 namespace after all.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    11

    Re: [Resolved] reading reg values

    ah cheers, just edited the references to v1.1 and its broke other stuff, will fix that. Cheers

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