Access files in C: \\ giving error: Access to path (...) was denied

1

I'm doing a program in C #, which needs to access all files and folders on the computer. It turns out that when I go to access a folder or file near C:\ , it says this message:

  

Access to path 'C: \ 2953323222e00ecf35c7' has been denied.

How can I access all folders and files without giving this problem? Running as administrator does not resolve.

    
asked by anonymous 10.11.2017 / 14:08

1 answer

5

Use the class System.Security.AccessControl.DirectorySecurity to request access as an administrator. Applications authenticate to have administrator permissions in this way, not just being run as administrator.

The code should look like this:

string user = "X"; // Troque X pelo nome de usuário de um administrador.
System.IO.DirectoryInfo folderInfo = new IO.DirectoryInfo("C:53323222e00ecf35c7");
DirectorySecurity ds = new DirectorySecurity();

ds.AddAccessRule(New FileSystemAccessRule(user, FileSystemRights.Modify, AccessControlType.Allow));
ds.SetAccessRuleProtection(false, false);
folderInfo.SetAccessControl(ds);

If the above code does not resolve as it is, take a look at the documentation to get the exact permission you need.

Credits - I got the code for this question in the English OS:

Visual Basic .NET Access to the path 'C: \' is denied

    
10.11.2017 / 14:28