VB.NET directory.EnumerateFiles:拒绝访问路径 X [英] VB.NET directory.EnumerateFiles: Access to path X is denied

查看:22
本文介绍了VB.NET directory.EnumerateFiles:拒绝访问路径 X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在尝试编写一个程序来查找 C 驱动器上的特定文件并获取其位置.但是下面的代码不起作用!我对此进行了大量研究,并从 GetFiles 转到 Directory.enumerateFiles.但是我一直遇到一个异常,声称我没有访问权限,只是忽略消息(关闭它/按确定)不会继续搜索而是完全停止搜索,如果可能的话,我需要一种绕过这个的方法,所以如果一个目录导致异常,如果可能,它将跳过它并在屏幕上没有错误的情况下移动.目前清单文件设置为requireAdministrator",所以我知道这不是问题.以管理员身份运行VB不解决,以管理员身份运行编译文件也不起作用.希望有人能帮忙!注意:我使用的是 Visual Basic 2010 Express,由于硬件限制和操作系统,我没有升级到新版本的计划.

Ok so I am trying to write a program to find a specific file on the C drive and get its location. However the following code does not work! I've researched this a lot and gone from GetFiles to Directory.enumerateFiles. However I keep running into an exception claiming that I have no access, simply ignoring the message (closing it/pressing ok) does not continue the search and instead stops it altogether, I need a way of bypassing this if possible, so If a directory causes an exception it will skip it and move along with no error on screen if possible. Currently the manifest file is set to "requireAdministrator" so I know thats not the issue. Running VB as administrator does not solve, and running the compiled file as admin does not work either. Hope someone can help! Note: I'm using Visual Basic 2010 Express and have no plans to upgrade to a newever version due to hardware limitation and operating system.

Imports System.IO

公共类 GuardianScanner

Public Class GuardianScanner

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox1.ReadOnly = True
    TextBox1.ScrollBars = ScrollBars.Vertical

    Button1.Enabled = False
    TextBox1.AppendText(Environment.NewLine & "[INFO] Please wait while scanning. This can take a few minutes")
    Try

        For Each file As String In Directory.EnumerateFiles("C:\", "GodlyNorris.exe", SearchOption.AllDirectories)

                TextBox1.AppendText(Environment.NewLine & "[INFO] Found virus: AUTONORRIS: " & file.ToString)





        Next file

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

推荐答案

我尝试将此作为评论发布,但它非常混乱.这应该可以工作,基本上它会尝试从 C 驱动器中的每个子目录中创建一个目录,如果它因未授权访问异常而失败,它会移动到下一个子目录.

I tried posting this as a comment but it's pretty messy. This should work, basically it tries to create a directory out of every subdirectory in the C drive, and if it fails with the unauthorized access exception, it moves on to the next subdirectory.

For Each directory In New DirectoryInfo("C:\").GetDirectories()
    Try
        For Each file In directory.GetFiles("*", SearchOption.AllDirectories)
            Try
                TextBox1.Text += Environment.NewLine + file.Name
            Catch ex As Exception
                'MsgBox(ex.Message)
                Continue For
            End Try
        Next
    Catch ex As Exception
        'MsgBox(ex.Message)
        Continue For
    End Try
Next

这篇关于VB.NET directory.EnumerateFiles:拒绝访问路径 X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆