Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET 2008 Delete reg key Access error

Posted on 2010-09-09
10
Medium Priority
?
386 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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 2000 total points
ID: 33646258
0
 
LVL 4

Author Closing Comment

by:CraigLazar
ID: 33668845
Thanks
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

636 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