2014-01-06 6 views
2

업데이트 2Windows API Code Pack을 사용하여 휴지통에 저장된 Item의 'Deletion Date'속성을 검색하는 방법은 무엇입니까?

마지막으로 나는 휴지통으로에 삭제 된 파일에 대한 액세스로가는 길 bymyself 찾은 WindowsAPICodePack 인터페이스의 대부분을 테스트.

유일한 문제는 지금은 각 파일의 삭제 날짜를 검색하는 데 필요한 속성 모음을 액세서 (및 폴더를 링크)하는 방법을 알아야한다는 것입니다,이 샘플 코드 :

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이 도움이 될 수 있습니다. 대부분의 셸 인터페이스를 광범위하게 (전체적으로) 구현합니다. 주어진 래퍼에서 사용하지 않으려면 코드 팩 항목 (InternalsVisibleTo 응용 프로그램 매니페스트 특성을 열거 나 모든 내부 인터페이스를 외부로 변경해야합니다)을 사용해야합니다.

삭제 날짜는 쉘 항목의 속성 가방에 들어 있습니다.
시간의 시작부터 마이크로 소프트의 개발자였던 개인적으로 윈도우 셸을 탄생시킨 위대한 레이몬드 첸 (Raymond Chen)은 C++로 그것을 수행하는 방법에 대한 완벽한 워크 쓰루 문서를 썼다. 'How can I get information about the items in the Recycle Bin?'

약간의 논리적 공제를 통해 필요한 비트를 가져 와서 자신의 관리되는 구현을 생성 할 수 있습니다.

두 링크 사이에는 이제 문제를 해결 한 다음 모든 지식을 소유하고 있습니다. 아이템의 DateDeleted 속성을 검색하려면

+0

먼저 답장에 늦어서 감사 드리며 죄송합니다. 1.URL 문서를 3 번 ​​읽은 후에는 저에게 도움이 될만한 것을 찾을 수 없습니다 (이것은'C/C++ 프로그래머가 아니기 때문에입니다, 죄송합니다). 단지'IShellFolder' 인터페이스를 사용하는 것으로 볼 수 있습니다 다른 것들은 나를 도울 수 있는지 이해할 수 없습니다. 2. 'WindowsAPICodePack'을 가끔 사용하지만 작업 표시 줄의 경우에는 'WindowsAPICodePack'을 사용하여 휴지통에 들어가는 방법을 모르지만 실제로는 도움이되는 솔루션을 사용하여 주시면 감사하겠습니다. – ElektroStudios

+0

그런데'내부 인터페이스 '를 소스 ('ShellCOMInterfaces.cs' 파일에있는)에서'공용 인터페이스'로 바꾸려고 시도했지만 컴파일러가'내부 인터페이스 '에서 많은 가시성 오류와 메타 데이터 오류를 던졌습니다. windowsapicodepack.Shell.dll' assembly ... 'C#'을 관리하지 않아서 미안 하네. 내가 언급 한 내부 변경 사항들로 컴파일 된 새'Windows API Pack'을 제공 할 사람이 필요 하겠지만, 알고, 어쩌면 그것은 너무 많이 묻고있다. .. 다시 잘 감사드립니다. – ElektroStudios

+0

감사합니다. 내 질문에 대한 업데이트를 참조하십시오. – ElektroStudios

2

이 간단하다 :

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++을 사용하면 멋지 기 때문에 C++에서 철자를 쓰는 방법을 알고 있습니다. MSDN 문서를 사용하여 C++에서 대답을 찾아내는 것이 WindowsApiCodePack을 통해 터벅 터벅 걷는 것보다 쉽습니다. 이름을 기반으로 속성을 검색하는 메서드가 있다는 것을 알지 못했습니다. :-) 플래그와 GUID를 사용합니다. –