2014-01-06 20 views
2

更新2如何使用Windows API代码包检索存储在回收站中的项目的“删除日期”属性?

最后测试的大部分WindowsAPICodePack接口,我发现bymyself的方式来存取权限的RECYCLEBIN删除的文件。

独特的现在的问题是我需要知道如何进入电影所需要的属性包检索每个文件的删除日期(以及文件夹和链接),这是一个示例代码:

Dim RecycleBin As IKnownFolder = KnownFolders.RecycleBin 

For Each File As ShellFile In (From Item As ShellObject In RecycleBin 
           Where Item.GetType = GetType(ShellFile)) 

    MsgBox(File.Name) 
    MsgBox(File.Properties.System.IsDeleted.Value) ' It's empty. 
    MsgBox(File.Properties.System.DateAcquired.Value) ' This is not the correct value. 
    MsgBox(File.Properties.System.DateArchived.Value) ' This is also not the correct value. 
    MsgBox(File.Properties.System.DateCompleted.Value) ' This is also not the correct value. 
    MsgBox(File.Properties.System.DateCreated.Value) ' This is also not the correct value. 
    MsgBox(File.Properties.System.DateImported.Value) ' This is also not the correct value. 

Next File 
+0

[访问回收站]的可能重复(http://stackoverflow.com/questions/13208338/accessing-the-recycle-bin) – Kurubaran

+0

不必须被报告为只有当复制问题其他问题有一个明显的答案或真正的解决方案?...因为不是这种情况,在另一个问题,这家伙没有回答关于删除日期的解决方案,因为我没有意识到这种情况下的这种报告。 – ElektroStudios

+1

@ElektroStudios它是否必须通过'WindowsAPICodePack'获得?被删除的日期和原始路径相当可取。我只是不确定是否支持通过垃圾邮件进行侦听 - Recycler是那些特殊的系统对象之一 – Plutonix

回答

2

Windows API Code Pack可能对你有一些帮助。它具有大多数shell接口的更多(完整)实现。您将不得不打开代码包项目(InternalsVisibleTo应用程序清单属性,或者只是将所有内部接口更改为外部),以便使用它们远离给定的包装。

至于删除日期:包含在shell项目的属性包中。
伟大的Raymond Chen在开始的时候一直是微软的开发人员,他亲自催生了Windows Shell,他写了一篇完整的关于如何使用C++编写的文章,名为'How can I get information about the items in the Recycle Bin?'

通过一点逻辑推理,您可以将需要的位拿走,并生成自己的托管实现。

在这两个环节之间,你现在拥有所有的知识来解决你的问题,然后一些。

+0

首先感谢您的评论,谢谢您的回答。 1。在阅读url文档3次后,我找不到任何可以帮助我的东西(这是因为我不是'C/C++'程序员,对不起),我只看到它只是使用'IShellFolder'接口来做其他的东西,但我不明白,如果这可以帮助我。 2.我有时使用'WindowsAPICodePack',但是对于任务栏的东西,我真的不知道如何使用'WindowsAPICodePack'进入回收站,但是真的,我会很欣赏使用它的解决方案,它可以帮助我。 – ElektroStudios

+0

顺便说一下,我试图将源代码中的所有'内部接口'更改为'public interface'(完全在'ShellCOMInterfaces.cs'文件中),但是编译器会在' windowsapicodepack.Shell.dll' assembly ...抱歉,我没有管理'C#'然后我可能需要一个人,可以为我提供一个新的'Windows API Pack'编译正确的内部更改,你已经提到,但我知道,也许这是要求太多...再次感谢。 – ElektroStudios

+0

如果可以,请参阅我的问题更新,谢谢。 – ElektroStudios

2

方式检索项目的DateDeleted性质很简单,因为这:

Private Sub Test() Handles MyBase.Shown 

    ' Get all the desired deleted items inside the Recycle Bin using WindowsAPICodePack. 
    ' (In my case I only retrieve the deleted files excluding folders.) 
    Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files 

    ' Loop through the deleted Items. 
    For Each Item As ShellFile In RecycledFiles 

     ' Append the full name 
     sb.AppendLine(Item.Name) 

     ' Append the DateDeleted. 
     sb.AppendLine(Item.Properties.GetProperty("DateDeleted").ValueAsObject.ToString) 

     MsgBox(sb.ToString) 
     sb.Clear() 

    Next Item 

End Sub 

然后检索forexample最后删除的文件:

''' <summary> 
''' Gets the last deleted file inside recycle bin. 
''' </summary> 
''' <returns>ShellFile.</returns> 
Public Shared Function GetLastDeletedFile() As ShellFile 

    Return (From Item As ShellFile In GetDeletedItems(Of ShellFile)(Nothing) 
      Order By Item.Properties.GetProperty("DateDeleted").ValueAsObject).Last 

End Function 

而且在这个片段中,我们可以获取其他财产名称和数值:

Dim sb As New System.Text.StringBuilder 

Private Sub Test() Handles MyBase.Shown 

    ' Get all the desired deleted items inside the Recycle Bin using WindowsAPICodePack. 
    ' (In my case I only retrieve the deleted files excluding folders.) 
    Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files 

    ' Loop through the deleted Items. 
    For Each Item As ShellFile In RecycledFiles 

     ' Append the full name (It's String type) 
     sb.AppendLine(Item.Name) 

     ' Loop through the Item properties. 
     For Each prop In Item.Properties.DefaultPropertyCollection 

      ' Append an empty line 
      sb.AppendLine() 

      ' Append the property name (It's String type) 
      sb.Append(prop.CanonicalName) 

      ' Append the property value (It's a generic Object type) 
      If prop.ValueAsObject IsNot Nothing Then 
       sb.Append(" = " & prop.ValueAsObject.ToString) 
      Else 
       sb.Append(" = NULL") 
      End If 

      MsgBox(sb.ToString) 

     Next prop 

    Next Item 

End Sub 

只是另一个例如:

Private Sub Test() Handles MyBase.Shown 

    ' Get all the deleted items inside the Recycle Bin using WindowsAPICodePack. 
    Dim RecycledItems As ShellObject() = RecycleBin.MainBin.Items 

    ' Loop through the deleted Items (Ordered by Deletion Date). 
    For Each Item As ShellFile In (From itm In RecycledItems 
            Order By itm.Properties.GetProperty("DateDeleted").ValueAsObject Ascending) 

     ' Append the property bags information. 
     sb.AppendLine(String.Format("Full Name: {0}", 
            Item.Name)) 

     sb.AppendLine(String.Format("Item Name: {0}", 
            Item.Properties.GetProperty("System.ItemNameDisplay").ValueAsObject)) 

     sb.AppendLine(String.Format("Deleted From: {0}", 
            Item.Properties.GetProperty("DeletedFrom").ValueAsObject)) 

     sb.AppendLine(String.Format("Item Type: {0}", 
            Item.Properties.GetProperty("System.ItemTypeText").ValueAsObject)) 

     sb.AppendLine(String.Format("Item Size: {0}", 
            Item.Properties.GetProperty("System.Size").ValueAsObject)) 

     sb.AppendLine(String.Format("Attributes: {0}", 
            [Enum].Parse(GetType(IO.FileAttributes), 
               Item.Properties.GetProperty("System.FileAttributes").ValueAsObject.ToString))) 

     sb.AppendLine(String.Format("Date Deleted: {0}", 
            Item.Properties.GetProperty("DateDeleted").ValueAsObject)) 

     sb.AppendLine(String.Format("Date Modified: {0}", 
            Item.Properties.GetProperty("System.DateModified").ValueAsObject)) 

     sb.AppendLine(String.Format("Date Created: {0}", 
            Item.Properties.GetProperty("System.DateCreated").ValueAsObject)) 

     MsgBox(sb.ToString) 
     sb.Clear() 

    Next Item 

End Sub 
+1

请注意该属性的规范名称是System.Recycle.DateDeleted,它(隐约)记录在这里:http://msdn.microsoft.com/en-us/windows/bb776504.aspx –

+0

这非常酷。我开始以非托管的方式学习API,当使用C++时很酷,所以我知道API是C++阐述的方式。对于我来说,使用MSDN文档在C++中搜索答案比在WindowsApiCodePack中寻找像这样愚蠢的答案更容易。我什至不知道有一种方法来检索基于名称的属性...... :-)我使用标志和GUID。 –

相关问题