By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Reading a Registry Key

P: n/a
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?
Nov 21 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
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

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

"Larry Bird" <La*******@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
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?
Nov 21 '05 #2

P: n/a
I tried the code that you provided and I'm still getting the same results.
Could there something else I'm missing here?

I was reading further and ran across something about permissions. could
this be the problem?

Thanks

"Ken Tucker [MVP]" wrote:
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

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

"Larry Bird" <La*******@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
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?

Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

P: n/a
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

"Cor Ligthert" wrote:
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

Nov 21 '05 #5

P: n/a
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

"Larry Bird" <La*******@discussions.microsoft.com>
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

"Cor Ligthert" wrote:
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

Nov 21 '05 #6

P: n/a
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?

"Cor Ligthert" wrote:
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

Nov 21 '05 #7

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

Thanks
"Cor Ligthert" wrote:
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

"Larry Bird" <La*******@discussions.microsoft.com>
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

"Cor Ligthert" wrote:
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


Nov 21 '05 #8

P: n/a
> 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
Nov 21 '05 #9

P: n/a
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
"Ken Tucker [MVP]" wrote:
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

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

"Larry Bird" <La*******@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
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?

Nov 21 '05 #10

P: n/a
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

"Cor Ligthert" wrote:
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

Nov 21 '05 #11

P: n/a
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.

"Cor Ligthert" wrote:
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

Nov 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.