Results 1 to 11 of 11

Thread: [2005] retrieving a file path from the registry

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    12

    [2005] retrieving a file path from the registry

    I searched the forums and msdn but especially the last didnt help me much.
    I want a simple retrieval of the installation location of another program. I look up the url and it's: HKEY_CURRENT_USER\Software\FTDv3.7.3

    I tried putting in the RegGetValue() and LONG RegQueryValueEx() but those aren't recognized by VS 2005. Then I searched the forums and found something like this:
    Code:
    Dim thekey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\FTDv3.7.3").GetValue("Standaard")
    MsgBox(thekey)
    but there is a problem with the last part, getvalue isnt correct and the original poster used setvalue but I do not want to set. The error is that i get an empty msgbox.

    I use (Standaard) because that is what the name of the first and only REG_SZ is. But that's dutch for default so I guess I need something else.

    I hope someone is willing to help although you probably think I should search harder, but really cant find the answhere:S.
    Thanks in advance.
    Last edited by sdk1985; May 1st, 2007 at 01:26 PM.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] retrieving a file path from the registry

    Are you sure there is supposed to be 2 As in standard?

    I just tried your line of code against a registry value and it got me the value back.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    12

    Re: [2005] retrieving a file path from the registry

    Quote Originally Posted by Negative0
    Are you sure there is supposed to be 2 As in standard?

    I just tried your line of code against a registry value and it got me the value back.
    I just edited my message 1 second ago, saw it too late sorry.
    It's dutch for default. I double clicked and it has no name in the upperbox.
    I'm not sure if this is the right translation but it says after double click:
    Valuename: (and then grey/nothing)
    Valuedata: D:\Program Files\FTDv3.7.2 (editable)

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] retrieving a file path from the registry

    Also, you should declare your variables as a type and use the MessageBox.Show function instead of msgbox.

    Code:
    Dim thekey As String = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\MyCompany\MySoftware").GetValue("MyRegString")
            MessageBox.Show(thekey)

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    12

    Re: [2005] retrieving a file path from the registry

    Quote Originally Posted by Negative0
    Also, you should declare your variables as a type and use the MessageBox.Show function instead of msgbox.

    Code:
    Dim thekey As String = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\MyCompany\MySoftware").GetValue("MyRegString")
            MessageBox.Show(thekey)
    Thanks. The final solution is easier then I thought:

    Dim thekey As String = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\FTDv3.7.3").GetValue("")
    MessageBox.Show(thekey)

    I just used "" to represent the empty name and it works.

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] retrieving a file path from the registry

    Ahh, so its the default registry key. Try using:

    Code:
    .GetValue("")

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    12

    Re: [2005] retrieving a file path from the registry

    Could you also help me with the application?

    Code:
    Dim thekey As String = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\FTDv3.7.3").GetValue("")
    
    OpenFileDialog1.InitialDirectory(thekey)
    error: property acces must assign to the property or use its value.

  8. #8
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] retrieving a file path from the registry

    The error is telling you that you need to assign to the property (i.e. it is not a method)
    Code:
    OpenFileDialog1.InitialDirectory = thekey

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    12

    Re: [2005] retrieving a file path from the registry

    Quote Originally Posted by Negative0
    The error is telling you that you need to assign to the property (i.e. it is not a method)
    Code:
    OpenFileDialog1.InitialDirectory = thekey
    Ok thanks, my final question about registry keys for now:
    how can I check if the registry key exists, according to the intelligent vb 2005 system there is no exist method.
    I think I cannot use

    If Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\FTDv3.7.3").Equals "" is false then...

    because the first name is empty but it does exist.

    The reason I would like to know is that it's possible that a feature user starts up the application without having that registry string in it's register. It will probably crash now if that happens because I'm trying to set the default directory of the openfiledialog to that location immediately at the form load.
    Last edited by sdk1985; May 1st, 2007 at 04:11 PM. Reason: typo

  10. #10
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] retrieving a file path from the registry

    The MSDN has a good bit of info on reading from the registry:

    http://msdn2.microsoft.com/en-us/lib...ta(VS.80).aspx

  11. #11
    Lively Member
    Join Date
    Feb 2006
    Posts
    125

    Re: [2005] retrieving a file path from the registry

    The exist method would look like
    Code:
    regVersion = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", True)
                If regVersion Is Nothing Then
                    'key doesn't exist, create it.

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