C # - Access Denied Windows Files

2

Hello, I'm doing software that can scan certain Windows files, where I leave certain types of extensions in it, but when I put it to scan the following access denied message in certain folders.

The code would be as follows:

DirectoryInfo dir_Local = new DirectoryInfo(tb_UnidadeHD.Text);

string[] extensao = new string[] { "*.WsF", "*.lnk", "*.vbs", "*.vbe", "*.js", "*.com" };
string[] dir_Info = Directory.GetFiles(tb_UnidadeHD.Text, extensao.ToString(), SearchOption.AllDirectories); ;            

try
{
    foreach (string procura in dir_Info)
    {
        lb_Arquivos.Text = string.Format("Escaneando: {0}", procura);
        string result = ScanForVirus(procura);

        if (!dir_Local.Exists)
            MessageBox.Show(string.Format("Diretório de origem não existe ou não pôde ser encontrado: {0}", dir_Local), "AlegoTools", MessageBoxButtons.OK, MessageBoxIcon.Error);
        else
        {
            if (result != string.Empty)
                listBox_Files.Items.Add(result);                            
            else
                MessageBox.Show(string.Format("Não foi encontrado nenhum vírus em {0}", dir_Local), "AlegoTools", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
catch { }

If you can give me a light, because I tried other means but without success, it simply can not scan certain parts of the windows, even if it is admin, it shows as if it is not accessed by the program, and it is configured to run as administrator

    
asked by anonymous 04.05.2016 / 18:33

1 answer

2

Apparently and only a folder permission problem, you can try checking the permissions by accessing the properties on the Security tab you can check permissions on the folder.

Example

Handlingtheexception

Astheuserdoesnothaveaccessthewayandnotifyhimabouthispermissionandifitallowstheaccesstohimthedesiredfolder.

Code

catch(UnauthorizedAccessExceptionex){MessageBox.Show("No Momento Você Não Tem permissões para realizar esta operação , Contate o Administrador Do Sistema  ! Detalhes : " + ex.Message, "Alerta ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
    
04.05.2016 / 19:12