• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

VB.NET 2008 Delete reg key Access error

Hi,
I have created a 1 button app that must simply delete a key and its sub keys from the registry in the LocalMachine section. But i am getting an access error.
{"Requested registry access is not allowed."}
Security Exception was caught.

            Dim x As Microsoft.Win32.RegistryKey
            x = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Test1", True)
            x.DeleteSubKeyTree("Testing")

The exception is being generated on line 2 of my code. Is there perhaps another way of doing it? (I have admin wrights on my machine Win7) I need to cater for XP,Vista and Win7n machines

thanks

0
CraigLazar
Asked:
CraigLazar
1 Solution
 
nepaluzCommented:
where have you defined the subkeytree "Testing" thatyou are trying to delete?
0
 
CraigLazarAuthor Commented:
Hi,
I am getting the error on the following line before i even attempt to delete the sub key
x = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Test1", True)

 
0
 
nepaluzCommented:
have you written that key?

Try the following to see what the value of the key is. If it is "0" then the value is not present


Dim uKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Test1", True)
                Dim cKey As String = CStr(uKey.GetValue("Testing", "0"))

Open in new window

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
CraigLazarAuthor Commented:
hi,
ok i tried ur code, but throws exception 'Requested registry access is not allowed'
0
 
nepaluzCommented:
what platform are you running the code on? Win7?
0
 
CraigLazarAuthor Commented:
win7 x64 VS2008
0
 
andr_ginCommented:
Have you turned UAC off?
With UAC on Windows 7 even a user with admin rights cannot access the HKLM tree for writing.

Do you have the same problem with a key in HKCU?
0
 
CraigLazarAuthor Commented:
Hi,
I turned UAC off and still same error.
0
 
ZhaolaiCommented:
0
 
CraigLazarAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now