This project is read-only.

Accesss Denied on some system Folders

May 25, 2011 at 12:12 AM

Trying to GetDirectories from some Folders throws an Access Denied Exception. It actually doesn't throw it cause the code catch this at Directory.cs -> public static IEnumerable<FileSystemEntryInfo> GetFullFileSystemEntries

Trying for example the folder "C:\Windows\CSC\v2.0.6" you will see that it retuns 0 Directories and an exception is catched..

Trying to browsing through windows explorer and windows will ask you to get permisions...

 

I need to read the files\Directories without forcing to get permissions, something like using BackupSemantics, however i do not wish to use FileStream.

Imagine that i enumerate the folder/subdirectories of 2 Directories, comparing some properties like size, date etc.. And finaly syncing Source --> Destination.

Been trying for 5 hours now and still can't figure out what i'm missing.

 

 

Ps. Just for reference a little bug of the Framework is that if you run code(x86) on a x64 machine you will also miss some results...
Explained here http://www.codeproject.com/Questions/198423/DirectoryInfo-GetDirectories-misses-some-Directori.aspx

May 25, 2011 at 5:15 AM

check the security enabler in the sub namespaceof alphaleonis. permissions you need are backup and restore. And callind
process shpuld be admin or backup operator to be able to elevate those security flags. Use with using() {} clause.
Can give you specific example tpmorrpw. Im on android now, cannot type correctly :)

On May 24, 2011 6:12 PM, "BeStelios" <notifications@codeplex.com> wrote:
> From: BeStelios
>
> Trying to GetDirectories from some Folders throws an Access Denied Exception. It actually doesn't throw it cause the code catch this at Directory.cs -> public static IEnumerable<FileSystemEntryInfo> GetFullFileSystemEntriesTrying for example the folder "C:\Windows\CSC\v2.0.6" you will see that it retuns 0 Directories and an exception is catched..Trying to browsing through windows explorer and windows will ask you to get permisions... I need to read the files\Directories without forcing to get permissions, something like using BackupSemantics, however i do not wish to use FileStream.Imagine that i enumerate the folder/subdirectories of 2 Directories, comparing some properties like size, date etc.. And finaly syncing Source --> Destination.Been trying for 5 hours now and still can't figure out what i'm missing. Ps. Just for reference a little bug of the Framework is that if you run code(x86) on a x64 machine you will also miss some results...
> Explained here http://www.codeproject.com/Questions/198423/DirectoryInfo-GetDirectories-misses-some-Directori.aspx
>
>
May 25, 2011 at 11:36 AM

Yes...
Now it's working, better than intended.

 Explorer Properties on c Windows : 107.293 Files , 25.988 Folder

 Alphafs Properties on c Windows : 107.296 Files , 25.990 Folder

3 more files and 2 more Directories.

Is this possible ?


Using (new Alphaleonis.Win32.Security.PrivilegeEnabler(Privilege.Backup, Privilege.Restore))
{
List<FileInfo> ListFiles = new List<FileInfo>();
List<DirectoryInfo> ListDirs = new List<DirectoryInfo>();
string m_SourcePath = "c:\\Windows";
DirectoryInfo SourceRoot = new DirectoryInfo(m_SourcePath);

               foreach (FileInfo File2 in SourceRoot.GetFiles())
               {
                   ListFiles.Add(File2);
               }
               DirectoryInfo[] Directories = SourceRoot.GetDirectories("*",System.IO.SearchOption.AllDirectories);

                   foreach (DirectoryInfo Dirs in Directories)
                   {
                       ListDirs.Add(Dirs);
                       foreach (FileInfo File2 in Dirs.GetFiles())
                       {
                           ListFiles.Add(File2);
                       }
                   }
               }

*Make sure you run this on a  "Platform Target any Cpu" = "Any Cpu"

And thanks for your fast response..
Btw i really find your code pretty elegant after some browsing on the source..You've done an excelent job.

 

May 25, 2011 at 9:29 PM
Well there are many things like symbolic links, hard links, special
files that you can't easily find out about using standard Windows
tools like Explorer properties, dir or something else.
For faster and more easy way to enumerate file system use
Alphaleonis.Win32.Filesystem.Directory.GetFullFileSystemEntries(string,
string, System.IO.SearchOption)
method and it's overloads. very easy, low on memory and returns every
single Files system object.
If you use in conjuctio with
Alphaleonis.Win32.Filesystem.Path.GetLongPath(string)
then you will get even more files and directories :)

Thank you for using Alphaleonis. We are always open for more feature
requests and bug reports.


Sincerely,
Alexandr Normuradov
425-522-3703



On 25 May 2011 05:36, BeStelios <notifications@codeplex.com> wrote:
> From: BeStelios
>
> Yes...
> Now it's working, better than intended.
>
>  Explorer Properties on c Windows : 107.293 Files , 25.988 Folder
>
>  Alphafs Properties on c Windows : 107.296 Files , 25.990 Folder
>
> 3 more files and 2 more Directories.
>
> Is this possible ?
>
> Using (new Alphaleonis.Win32.Security.PrivilegeEnabler(Privilege.Backup,
> Privilege.Restore))
> {
>
> List<FileInfo> ListFiles = new List<FileInfo>();
> List<DirectoryInfo> ListDirs = new List<DirectoryInfo>();
> string m_SourcePath = "c:\\Windows";
> DirectoryInfo SourceRoot = new DirectoryInfo(m_SourcePath);
>
> foreach (FileInfo File2 in SourceRoot.GetFiles())
> {
> ListFiles.Add(File2);
> }
> DirectoryInfo[] Directories =
> SourceRoot.GetDirectories("*",System.IO.SearchOption.AllDirectories);
>
> foreach (DirectoryInfo Dirs in Directories)
> {
> ListDirs.Add(Dirs);
> foreach (FileInfo File2 in Dirs.GetFiles())
> {
> ListFiles.Add(File2);
> }
> }
> }
>
> *Make sure you run this on a  "Platform Target any Cpu" = "Any Cpu"
>
> And thanks for your fast response..
> Btw i really find your code pretty elegant after some browsing on the
> source..You've done an excelent job.
>
>
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe or change your settings on codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at codeplex.com