473,834 Members | 1,874 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 1674
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
5914
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
3472
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
5030
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
1953
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
17862
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
1466
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
5092
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
1802
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
4010
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
9799
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9646
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
10793
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...
1
10548
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,...
0
9331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7758
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
6954
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
5627
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.