繁体   English   中英

VB.NET目录。EnumerateFiles:拒绝访问路径X

[英]VB.NET directory.EnumerateFiles: Access to path X is denied

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

Imports System.IO

公共类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驱动器的每个子目录中创建一个目录,如果由于未授权的访问异常而失败,则它将移至下一个子目录。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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