Solved

VB.NET 2008 Delete reg key Access error

Posted on 2010-09-09
10
371 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
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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now