Question

In a Windows Application I have, I am doing some changes in registry like deleting a particular key, in some test scenarios like in a Vista machine with its UAC put on, I'm getting System.UnauthorizedAccessException. My code would look something like this:

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

But the application would still go crashing., not being handled by the catch block. Is there some way I could handle it?

Was it helpful?

Solution

You're probably throwing another exception from the catch block. Try commenting all lines in the catch block and it should work just fine.

OTHER TIPS

Most common and obvious reason is that the path / file program is trying access doesn't have access to the identity under which its running.

Read more here on MSDN

you have to set admin access for your application

for that just right click and select properties

and check Run as Administrator check and run your application

to run as administrator for all users click on all user button and select run as administrator for all users this will always run your application with admin access for all users

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top