Accessing files in C: error: Access to path (...) has been denied

Asked

Viewed 4,637 times

2

I am making a program in C#, which needs to access all files and folders from the computer. It turns out that when I go to access a folder or file near C:\, he says this message:

Access to path 'C: 2953323222e00ecf35c7' was denied.

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

  • running as administrator

  • @Rovann Linhalis I ran as an administrator, not Ressoulveu.

  • what is 2953323222e00ecf35c7 ? a briefcase ?

  • @Rovannlinhalis Yes

  • possibly is a protected operating system folder, you need to access it or you can ignore it ?

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, and not just running as administrator.

The code should look like the following:

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

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

If the above code doesn’t resolve as is, take a look at the documentation to get the exact permission you need.

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.