473,782 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Registry reading error

I am using the following code to read from and write to the registry.
The writing works fine but reading always fails. Can anyone suggest
what is going wrong?

Imports Microsoft.Win32

Public Class clsRegistry

Private Const conRegKey As String =
"Software\MyCom pany\MyApplicat ion"
Public Sub New()
Dim rgKey As RegistryKey = Registry.Curren tUser
Dim strStr As String

rgKey.OpenSubKe y(conRegKey)
strStr = rgKey.Name
If strStr = "HKEY_CURRENT_U SER" Then
'create the subkey
rgKey.CreateSub Key(conRegKey)
End If
rgKey.Close()
End Sub

Public Function GetProject() As String
Dim rgKey As RegistryKey = Registry.Curren tUser
Dim str As String

rgKey.OpenSubKe y(conRegKey)
str = rgKey.GetValue( "MyKeyVal", "fail")
'always returns "fail"
GetProject = str
rgKey.Close()
End Function

Public Function SetProject(ByVa l str As String) As Boolean
Dim rgKey As RegistryKey = Registry.Curren tUser

rgKey = rgKey.OpenSubKe y(conRegKey, True)
rgKey.SetValue( "MyKeyVal", str)
rgKey.Close()
SetProject = True
End Function
End Class
Nov 20 '05 #1
1 1671
Hi,

RegistryKey.Ope nSubKey returns a registry key. Here is a quick
example on how to read a key.

Dim MyReg As RegistryKey = Registry.LocalM achine

Dim MyRegKey As RegistryKey

Dim MyVal As String

MyRegKey = MyReg.OpenSubKe y("Software\Mic rosoft\Windows NT\currentVersi on")

MyVal = MyRegKey.GetVal ue("ProductID" )

MyRegKey.Close( )

Ken

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

"Peter John" <p.*****@comput er.org> wrote in message
news:51******** *************** ***@posting.goo gle.com...
I am using the following code to read from and write to the registry.
The writing works fine but reading always fails. Can anyone suggest
what is going wrong?

Imports Microsoft.Win32

Public Class clsRegistry

Private Const conRegKey As String =
"Software\MyCom pany\MyApplicat ion"
Public Sub New()
Dim rgKey As RegistryKey = Registry.Curren tUser
Dim strStr As String

rgKey.OpenSubKe y(conRegKey)
strStr = rgKey.Name
If strStr = "HKEY_CURRENT_U SER" Then
'create the subkey
rgKey.CreateSub Key(conRegKey)
End If
rgKey.Close()
End Sub

Public Function GetProject() As String
Dim rgKey As RegistryKey = Registry.Curren tUser
Dim str As String

rgKey.OpenSubKe y(conRegKey)
str = rgKey.GetValue( "MyKeyVal", "fail")
'always returns "fail"
GetProject = str
rgKey.Close()
End Function

Public Function SetProject(ByVa l str As String) As Boolean
Dim rgKey As RegistryKey = Registry.Curren tUser

rgKey = rgKey.OpenSubKe y(conRegKey, True)
rgKey.SetValue( "MyKeyVal", str)
rgKey.Close()
SetProject = True
End Function
End Class

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5910
by: René Beumer | last post by:
I am trying to install a windows service written in .net 2003 on my Windows 2000 computer. I have followed the walkthru given in msdn but the service fails to install with 'requested registry access is not allowed' (using both InstallUtil or by creating an installer). I have tracked the registry access failure using RegMon and found that it fails on
2
3468
by: Joao Santa Barbara | last post by:
Hi all i have this error reading one registry key , can anyone assist me .. please very urgent i try in one computer, and work fine, but in other computer it didn´t work and throws this error ..??? "Request for the permission of type
1
5026
by: Duncan Allen | last post by:
I'm trying to use aspnet_setreg to encrypt user names & password used in the web.config file for use in the indentity element. When the website runs I get the message 'Error reading the password from the registry'. I'm using Windows XP SP2, Framework 1.1 . The code in the web.config file is : <identity impersonate="true" password="registry:HKLM\SOFTWARE\MyCompany\MyApp\Website\Identity\ASPNET_SETREG,password...
3
1947
by: Mike Malter | last post by:
On my XP Professional dev machine, I am able to read the registry by giving permissions to the ASP.NET account on the local machine. When I transfer the code to my staging server (Windows 2003), I am getting a System.Security.SecurityException: Requested registry access is not allowed. The key is there, I exported it from my XP machine. The permissions are there, and I can see in the error message the code breaks where I try to read...
6
17839
by: Bry | last post by:
I'm having problems writing (and reading) boolean data to the registry. // Write a boolean value to the registry // I've not included the obvious bits of code in these samples bool myBool = true; myRegistryKey.SetValue("SomeValue", myBool); This gives me a registry value with string data containing "True" // Read my boolean data back from the registry
6
1464
by: stephen coleman | last post by:
Hi all and thanks for reading this. I can read anywhere in the registry, but I can't write to the local machine (XP Pro, I am not the admin.). My application needs to write to the registry the registration code, but because of the permissions thing, it won't let me. Any ideas on how I can resolve this?? Many thanks, Steve.
5
5088
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I have it store info it gets from when the programs check in into a DataSet (XML file). Problem is, that file now has to be used by other programs to find out version information (the file is ALWAYS less that 1K.) The record itself is only five fields...
3
1797
by: Aussie Rules | last post by:
Hi, I want to store some data in the registry, however I have not been able to do this, and think my logic maybe flawed. Firstly I try to open the registry and read in any existing values. Dim aKey As RegistryKey aKey = Registry.CurrentUser.OpenSubKey("software\myApplication") I then attempt to read in any existing values
0
4005
by: tmsprowl | last post by:
Greetings! I was wondering if someone could help me with a problem I'm having. My department is just one of many within my organization. My organization has control over the network domain, but my department has a couple of web servers of our own that are part of my organization's domain. I am trying to read LDAP information on my organization's domain controller from a web application on one of my department's servers. I have been...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.