Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 27-Nov-12 17:41pm
v2

1 solution

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.
 
Share this answer
 
Comments
Nikhil@123 26-Nov-12 8:20am    
Sir,

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    
Sir,
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,
thanks.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900