# VS2010 VB app not catching UnauthorizedAccessException inside Try/Catch block

This topic is 2776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to enumerate through the root of my C:\ Drive on Vista, running under an admin account and also running the IDE as administrator, as well as having attempted to run the binary exe as administrator. No matter what I do, I (apparently properly) am denied access to C:\Documents and Settings, which I do not care about enumerating and which doesn't even show up in Explorer with hidden items shown. Anyway, in XP, to skip over folders the user didn't have access to I'd use the following code, which worked fine. However, on Vista, the try/catch block is NOT catching the UnauthorizedException. /confused

Any thoughts? The Framework's no good if a try/catch isn't going to catch an exception

Edit: I do realize I can work around it with an if statement to check for the specific folder, but what if the OS install drive is not C:\? What other folders are going to cause the same problem?

Sub SearchFolder(Folder As String)    Try        Dim Folders() As String = Directory.GetDirectories(Folder) ' UnauthorizedException here when trying to access C:\Documents and Settings, not being caught in the catch area        For Each f As String In Folders            SearchFolder(f)        Next    Catch ex As Exception        Stop    End Try    ' Other stuff done hereEnd Sub

[Edited by - LycaonX on October 20, 2010 9:47:29 AM]

• 10
• 17
• 9
• 14
• 41