Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 Smile | :)
 
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 dirListoffoldersinD = Directory.GetDirectories(@folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories).ToList();
progressbar1.Maximum = dirListoffoldersinD.Count();
Posted 26-Nov-12 1:28am
Edited 27-Nov-12 17:41pm
v2

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
Nikhil@123 at 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 at 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 at 27-Nov-12 1:34am
   
Sir,
I have tried Searching everywhere but cudnt find the answer not even hints..
Richard MacCutchan at 27-Nov-12 4:34am
   
Not even these hints?
Nikhil@123 at 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.
Richard MacCutchan at 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 at 28-Nov-12 8:11am
   
Sir can u share that code with me
Richard MacCutchan at 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 at 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 at 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
0 Sergey Alexandrovich Kryukov 418
1 OriginalGriff 344
2 George Jonsson 233
3 Shemeemsha RA 138
4 Animesh Datta 130
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
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