Solved

VB.NET 2008 Delete reg key Access error

Posted on 2010-09-09
10
379 Views
Last Modified: 2012-05-10
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
Comment
Question by:CraigLazar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 33635587
where have you defined the subkeytree "Testing" thatyou are trying to delete?
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 33635679
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
 
LVL 17

Expert Comment

by:nepaluz
ID: 33635824
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:CraigLazar
ID: 33637236
hi,
ok i tried ur code, but throws exception 'Requested registry access is not allowed'
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 33637351
what platform are you running the code on? Win7?
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 33638419
win7 x64 VS2008
0
 
LVL 5

Expert Comment

by:andr_gin
ID: 33645338
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
 
LVL 4

Author Comment

by:CraigLazar
ID: 33645401
Hi,
I turned UAC off and still same error.
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 33646258
0
 
LVL 4

Author Closing Comment

by:CraigLazar
ID: 33668845
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question