Delete folder from registry - permission problems

I am trying to delete one folder from the registry. Say I want to delete a folder

Software\TeamViewer 

I wrote the code, but it gives an exception "you cannot write." I assume this is some kind of issue with access rights and permissions.

 string keyapath = @"Software\TeamViewer"; RegistryKey regKeyAppRoot = Registry.CurrentUser.OpenSubKey(keyapath); regKeyAppRoot.DeleteSubKeyTree(keyapath); 

How do I allow my software to delete folders from the registry?

EDIT: I have administrator rights to my system. Should I still grant application rights only through my code?

+1
c # winforms registry
Jan 03 2018-12-01T00:
source share
3 answers

The OpenSubKey method with one parameter opens the key for reading. Use another variation of the OpenSubKey method:

OpenSubKey(String, Boolean) - pass true for the second parameter to open the shared key for writing

OpenSubKey(String, RegistryKeyPermissionCheck) - Allows you to precisely control access control for connections.

OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights) - As indicated above, but you can specify the necessary rights exactly.

See MSDN for more details.

+5
Jan 03 '12 at 14:57
source share

Your application requires admin rights to modify data in the registry. To obtain these rights, your mainfest of your application must contain some values ​​that indicate to the windows that the application requires more rights.

Google uac .net or uac c# (UAC = User Account Control)

Or just take a look at this article.

Create and implement an application manifest (UAC)

+2
Jan 03 '12 at 15:00
source share

You must create a manifest file in your project (right-click on the project, add a new element, manifest file). Then open it, inside you will see the following:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> // Put this to invoke UAC for admin rights </requestedPrivileges> </security> </trustInfo> </assembly> 

Then, when you run the application, it will offer uac, then the program will work as an administrator, hoping to give you the access you need.

Hope this helps!

+1
Jan 03 '12 at 15:31
source share



All Articles