Results 1 to 4 of 4

Thread: read from registry key multi-string value ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    467

    read from registry key multi-string value ?

    Hi,

    I have made this code and it does work with a normal string key, but with a multi-string value(REG_MULTI_SZ) key it does not :/

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim readValue As String
            readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\test", "test123", Nothing)
    
            For Each itemD As String In readValue
    
                ListBox1.Items.Add(itemD)
            Next
    
        End Sub
    The error is this : Conversion from type 'String()' to type 'String' is not valid.

    So how do i read from a multi-tring value registry key and list is all into the listbox ?

    Thanks

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

    Re: read from registry key multi-string value ?

    Do you have Option Strict On? I'm going to guess not. The value you get from GetValue is an object. You're implicitly converting an object to a string. Which is most likely the problem. If you cast the object to a string, then it should work.
    Last edited by weirddemon; Jan 1st, 2012 at 02:06 PM.
    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"....

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    467

    Re: read from registry key multi-string value ?

    Quote Originally Posted by weirddemon View Post
    Do you have Option Strict On? I'm going to guess not.
    Makes no difference, same error :/

    but if i use a normal registry key then it works fine, just not with mutli-string value

    Thanks

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

    Re: read from registry key multi-string value ?

    You should always keep Option Strict on as a good programming practice and to avoid possible mistakes later on.

    In the case of this issue, it's because a multi-string registry value is returned as an array. But you're not treating it as such.

    I did this which allowed me to find an example by JMC here. It took about 10 seconds to do so. Although I haven't tried the example myself, it looks fairly solid.

    *Edit: It works fine. Please do a little research next time before posting a question. It helps eliminate clutter such as this.
    Last edited by weirddemon; Jan 1st, 2012 at 02:16 PM.
    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