Link to home
Start Free TrialLog in
Avatar of CraigLazar
CraigLazar

asked on

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

Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

where have you defined the subkeytree "Testing" thatyou are trying to delete?
Avatar of CraigLazar
CraigLazar

ASKER

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)

 
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

hi,
ok i tried ur code, but throws exception 'Requested registry access is not allowed'
what platform are you running the code on? Win7?
win7 x64 VS2008
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?
Hi,
I turned UAC off and still same error.
ASKER CERTIFIED SOLUTION
Avatar of Zhaolai
Zhaolai
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks