How to handle UnauthorizedAccessException from user code

In a Windows application, I have some registry changes, such as deleting a certain key, in some test cases, for example, on a Vista machine with UAC enabled, I get a System.UnauthorizedAccessException . My code would look something like this:

 try { //delete registry keys } catch (UnauthorizedAccessException ex) { //handling } catch (Exception genEx) { //handling } 

But the application will still crash. Not handled by the catch block. Is there any way to handle this?

+6
source share
3 answers

You probably selected another exception from the catch block. Try commenting out all the lines in the catch block and it should work fine.

+1
source

The most common and obvious reason is that the path / file program is trying to access, it does not have access to the identifier in which it works.

Read more here MSDN

0
source

you need to set admin access for your application

to do this, simply right-click and select properties

and check the Run as administrator box and run the application

to run as administrator for all users, click on all user buttons and select run as administrator for all users, this will always launch your application with administrator access for all users

enter image description here

0
source

Source: https://habr.com/ru/post/904394/


All Articles