What is the best way to check for reparse point in .net (c#)?

馋奶兔 提交于 2019-12-23 17:31:02

问题


My function is pretty much a standard search function... I've included it below.

In the function I have 1 line of code responsible for weeding out Repart NTFS points.

if (attributes.ToString().IndexOf("ReparsePoint") == -1)

The problem is now I am getting an error Access to the path 'c:\System Volume Information' is denied.

I debugged the code and the only attributes at run time for this directory are :

  System.IO.FileAttributes.Hidden 
| System.IO.FileAttributes.System 
| System.IO.FileAttributes.Directory

I'm executing this code on a windows 2008 server machine, any ideas what I can do to cure this failing?

public void DirSearch(string sDir)
{
    foreach (string d in Directory.GetDirectories(sDir))
    {
        DirectoryInfo dInfo = new DirectoryInfo(d);
        FileAttributes  attributes = dInfo.Attributes;
        if (attributes.ToString().IndexOf("ReparsePoint") == -1)
        {
            foreach (string f in Directory.GetFiles(d, searchString))
            {
                //lstFilesFound.Items.Add(f);
                ListViewItem lvi;
                ListViewItem.ListViewSubItem lvsi;
                lvi = new ListViewItem();
                lvi.Text = f;
                lvi.ImageIndex = 1;
                lvi.Tag = "tag";
                lvsi = new ListViewItem.ListViewSubItem();
                lvsi.Text = "sub bugger";
                lvi.SubItems.Add(lvsi);

                lvsi = new ListViewItem.ListViewSubItem();
                lvsi.Text = d;//"C:\\Users\\Administrator\\Downloads\\MediaMonkey.GOLD.EDITION.v.3.0.2.1134.[Darkside].[Demonoid].[Grim.Reaper]";
                lvi.SubItems.Add(lvsi);

                listView1.Items.Add(lvi);
            }
            DirSearch(d);
        }
    }
}

回答1:


Nobody has permission to access System Volume Information except the SYSTEM account. So either change the permissions on the directory. Or much, much better catch the exception and go on.




回答2:


I'm not sure what the answer to the question is, but please change your attribute check to use proper bitwise operations!

if (attributes.ToString().IndexOf("ReparsePoint") == -1)

... is much more correctly written as ...

if ((attributes & FileAttributes.ReparsePoint) == 0)



回答3:


Perhaps this article could help you (they explain how to get access to this folder):

http://support.microsoft.com/kb/309531

The desperate solution is try - catch.




回答4:


Once you get past permissions, and really want to test for junction points, this class provides testing for, creating and deleting of junction points through the use of DeviceIoControl kernel32 call and analysis of the reparse point.



来源:https://stackoverflow.com/questions/332397/what-is-the-best-way-to-check-for-reparse-point-in-net-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!