检查 .net (c#) 中重新分析点的最佳方法是什么?

发布于 2024-07-10 03:31:46 字数 1609 浏览 5 评论 0原文

我的功能几乎是一个标准的搜索功能...我已将其包含在下面。

在该函数中,我有 1 行代码负责清除 Repart NTFS 点。

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

问题是现在我收到错误 访问路径“c:\System Volume Information”被拒绝。

我调试了代码,该目录在运行时的唯一属性是:

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

我正在 Windows 2008 服务器计算机上执行此代码,我能做些什么来解决这个失败吗?

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);
        }
    }
}

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);
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鸠书 2024-07-17 03:31:46

我不确定问题的答案是什么,但是更改您的属性检查以使用正确的按位运算!

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

... 更正确地写为 ...

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

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)
携余温的黄昏 2024-07-17 03:31:46

除 SYSTEM 帐户外,任何人都无权访问系统卷信息。 因此,要么更改目录的权限。 或者更好地捕获异常并继续。

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.

忆伤 2024-07-17 03:31:46

一旦您获得了权限,并且确实想要测试连接点,此类通过使用DeviceIoControl kernel32调用和分析重解析点来提供对连接点的测试、创建和删除。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文