简体   繁体   中英

Access to path is denied in vb.Net

I have a tool that manages the folders/files (eg file find, copy etc). The user select a root folder. I have a routine to find all the subfolders (subfolders of subfolders att all level) in the root folder. I use Directory.Getdirectories() method to obtain the subfolders. When i work in C directory i recieve 'Access to path is denid' exception. I overcome the exception by using on error resume next but this way the directory is skipped. I just want to obtain all directories with or without permission. The code in short is like below.

Thanks alot.

On error resume next

For each subfolder in directory.getdirectories(folderarray1(ifolder))
Directory.getdirectories(subfolder)

counter1=counter1 + 1
folderarray1(counter1) = subfolder
. 
.
.
Next subfolder

On error goto 0

The operating system has security mechanisms to prevent access to resources the current user should not be able to access.

If a program could just bypass them when it wants the security mechanisms would be pointless. And malware would do just that!

A program running on behalf of a user can only access the resources the user has access to.

TL;DR version: you cannot just bypass access control when you feel you want to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM