Reading a Registry Key

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to read a registry key using VB.Net. I have posted the code below
that I'm using:

Dim DBConnect As RegistryKey = Registry.CurrentUser.OpenSubKey _
("Software\VB and VBA Program Settings\Mobile Control\SageQuestSetup")
Dim AlertDB As String = CType(DBConnect.GetValue("ConnectionString"),
String)

Public AlertConnectionString As String = AlertDB

I've vaildated the key path and I continue to get nothing assigned to
DBConnect.

What am I doing wrong here?

Thanks

Are there more variables to set?
 
Hi,

Dim myReg As RegistryKey = Registry.LocalMachine

Dim MyRegKey As RegistryKey

Dim MyVal As String

MyRegKey = myReg.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")

MyVal = MyRegKey.GetValue("ProductID")

Trace.WriteLine(MyRegKey.GetValue("ProductID"))

Trace.WriteLine(MyRegKey.GetValue("RegisteredOwner"))

MyRegKey.Close()



Ken

----------------------------------

I'm trying to read a registry key using VB.Net. I have posted the code below
that I'm using:

Dim DBConnect As RegistryKey = Registry.CurrentUser.OpenSubKey _
("Software\VB and VBA Program Settings\Mobile Control\SageQuestSetup")
Dim AlertDB As String = CType(DBConnect.GetValue("ConnectionString"),
String)

Public AlertConnectionString As String = AlertDB

I've vaildated the key path and I continue to get nothing assigned to
DBConnect.

What am I doing wrong here?

Thanks

Are there more variables to set?
 
Larry,

Just from a program before my nose. (a very little bit changed)

Imports Microsoft.Win32

Dim Reg As RegistryKey = Registry.CurrentUser
Reg = Registry.CurrentUser.CreateSubKey("Software\FromMe\ThePart")
Me.ClientSize = New System.Drawing.Size(Reg.GetValue("Width",100),
Reg.GetValue("Height",100))

I hope this helps?

Cor
 
I have been really struggling with this since yesterday afternoon and no luck
yet. Here's a copy of my code. please tell me what I'm doing wrong.

Dim SageQuestRegistry As RegistryKey = Registry.CurrentUser

Dim SageQuestDB As RegistryKey

Dim AlertConnectionString As String

SageQuestDB = SageQuestRegistry.OpenSubKey _
("Software\VB and VBA Program Settings\Mobile
Control\SageQuestSetup")

AlertConnectionString = SageQuestDB.GetValue("ConnectionString")

SageQuestDB.Close()

I've verifed that the key does exist.


thanks
 
Larry,

Did you do it the way I do just creating that subkey before you read it?
As I remember me I did not get it to work as well not with your method.
(I am not sure anymore about this, however I thought as well that I saw
persons who did it like you and did not succeed).

The took the methode I take and they said than ........................

Cor
 
Could this be a case that I don't have permission to read the registry
entiry? If so how do I set the permissions to read?
 
For me the key already exist. So I'm trying to read a key created and is
being used in VB 6.

Thanks
 
For me the key already exist. So I'm trying to read a key created and is
being used in VB 6.

That does not matter

I use it forever in that way I showed you, did you try it already?

Cor
 
I tired the code example that you provided and things seem to work but? I'm
not sure why I needed to use an "CreateSubKey" vs a OpenSubkey since all I
want to do is read from the registry the specified key

However, a bigger issue has to do with the use of "GetValue" it doesn't
work. The only thing that it returns is the defaul value. I've checked to
make sure that the sub exist and results are the same. According to the
documentation the default value is not required but that is all that is
returned. In my case it also appears that ODBC connections do not work in
the .net world. I'm still investigating that.

Have you experience this type of behavior also?

Thanks
 
I tired the code example that you provided and things seem to work but? I'm
not sure why I needed to use an "CreateSubKey" vs a OpenSubkey since all I
want to do is read from the registry the specified key

However, a bigger issue has to do with the use of "GetValue" it doesn't
work. The only thing that it returns is the defaul value. I've checked to
make sure that the sub exist and results are the same. According to the
documentation the default value is not required but that is all that is
returned. In my case it also appears that ODBC connections do not work in
the .net world. I'm still investigating that.

Have you experience this type of behavior also?

Thanks
 
All the code the we exchanged will work. The real problem was security. The
user ID that is signed must have the right permission to read or write to the
registry.
 
Back
Top