Solved

VB.NET 2008 Delete reg key Access error

Posted on 2010-09-09
10
376 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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