|
-
May 1st, 2007, 01:20 PM
#1
Thread Starter
New Member
[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.
-
May 1st, 2007, 01:26 PM
#2
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.
-
May 1st, 2007, 01:28 PM
#3
Thread Starter
New Member
Re: [2005] retrieving a file path from the registry
 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)
-
May 1st, 2007, 01:28 PM
#4
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)
-
May 1st, 2007, 01:31 PM
#5
Thread Starter
New Member
Re: [2005] retrieving a file path from the registry
 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.
-
May 1st, 2007, 01:33 PM
#6
Re: [2005] retrieving a file path from the registry
Ahh, so its the default registry key. Try using:
-
May 1st, 2007, 01:37 PM
#7
Thread Starter
New Member
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.
-
May 1st, 2007, 01:42 PM
#8
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
-
May 1st, 2007, 04:06 PM
#9
Thread Starter
New Member
Re: [2005] retrieving a file path from the registry
 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
-
May 1st, 2007, 07:52 PM
#10
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
-
May 1st, 2007, 08:07 PM
#11
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|