Click here to Skip to main content
13,293,178 members (42,901 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi Friends,

I am working on a Project Called "Computer Scanner", till now i am done with coding in order to scan a Particular Folders and Files.Eventually, i have coded to scan my Hard Drive (C:\\, D:\\) as well so now, When i debug my project in order to scan my computers Hard Drives its giving me an error
"Access to the path 'D:\System Volume Information\' is denied."
So i wants to get rid of this Exception, After studing about this error from internet i got to know that these folders "System volume Information" creates when we create partition in our computers hard drives so it contain some Windows information so i would not be able to delete it. And i tried giving Admin Rights to my code in order to run, but still showing me the same exception.
So plz help me to scan these folders as well,,

Here is the Code.

Thanks in Advance :)

if (folderBrowserDialog1.SelectedPath == "D:\\")
//Giving Administration Authentication to the Program
WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal currentPrincipal = new WindowsPrincipal(currentIdentity);

if (currentPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
//Get all the Folders in Selected Path

List<string> dirListoffoldersinD = Directory.GetDirectories(@folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories).ToList();
progressbar1.Maximum = dirListoffoldersinD.Count();
Posted 26-Nov-12 2:28am
Updated 27-Nov-12 18:41pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is not an "error" that you can get rid of. System files are protected by access control so you need to change the permissions of the object to access it. Try searching Google for suggestions on how to do this.
Nikhil@123 26-Nov-12 8:20am

Yes sir i do understand its was an exception not an error,By the way, is there any other way where i can get access of all files and folders by running my code as a "Administrator", is there any class or object for Windows Administrator Role.
Richard MacCutchan 26-Nov-12 9:51am
If you have Administrator access then you can always run your program at that level. However, this folder is restricted to "System" access so you cannot normally get permission to access it. Try using Google to research this issue, maybe Microsoft has a white paper on the subject.
Nikhil@123 27-Nov-12 1:34am
I have tried Searching everywhere but cudnt find the answer not even hints..
Richard MacCutchan 27-Nov-12 4:34am
Not even these hints?
Nikhil@123 27-Nov-12 23:43pm
HI Sir,
I found the code which allows me to give Admin Rights to my code in order to run,
But still it showing me the same exception.
Plz help sir,
Richard MacCutchan 28-Nov-12 5:26am
That will not help you; you need to add access permissions to the objects themselves. The fourth link in the Google search results I provided above gives the information on how to do it. Be warned, however, that changing access rights on system controlled objects creates a security hole in your system.
Nikhil@123 28-Nov-12 8:11am
Sir can u share that code with me
Richard MacCutchan 28-Nov-12 9:06am
I don't have any code. I have already told you where the information is that explains how to change the ACL on these folders to give you access. You need to go and read it and follow the instructions. However, I would ask why you need access to this folder since it is a system protected area.
Nikhil@123 28-Nov-12 23:17pm
Sir i am working on project "Computer Scanner" so i waants to scan entire files and folders from Hard Drives no matter if such files belongs to system protected area but it should scan, is that why i need access to such Folders.
Richard MacCutchan 29-Nov-12 4:51am
Well, it is worth considering the fact that if your scanner cannot access these locations then other non-system applications cannot access them either.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100