嗯。好吧,在重新訪問PInvoke後,我確信我不太明白: - /(只是問了this question)再次引用shell32,C#Visual Studio
讓我說明我需要處理的代碼。當我使用「添加引用 - > COM - > Microsoft Shell控件和自動化」時它可以工作......但是很遺憾,它在我的項目中放置了一個引用,如下所示:「C:\ Users \ Tim \ Documents \ Visual Studio 2008 \ Projects \ Wing \ FileWing \ obj \ Debug \ Interop.Shell32.dll「
我正在挖掘回收站,並尋找我想要恢復的項目。有沒有辦法通過PInvoke來完成這個任務?或者獲取對system32/shell32.dll的引用,讓我可以在運行時使用此代碼?
private void recoverRecyclerBinEntry(string fileName, int size)
{
try
{
Shell Shl = new Shell();
Folder Recycler = Shl.NameSpace(10);
// scans through all the recyclers entries till the one to recover has been found
for (int i = 0; i < Recycler.Items().Count; i++)
{
FolderItem FI = Recycler.Items().Item(i);
string FileName = Recycler.GetDetailsOf(FI, 0);
if (Path.GetExtension(FileName) == "")
FileName += Path.GetExtension(FI.Path);
//Necessary for systems with hidden file extensions.
string FilePath = Recycler.GetDetailsOf(FI, 1);
string combinedPath = Path.Combine(FilePath, FileName);
if (size == FI.Size && fileName == combinedPath)
{
Debug.Write("Match found. Restoring " + combinedPath + "...");
Undelete(FI);
Debug.WriteLine("done.");
}
else
{
Debug.WriteLine("No match");
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
}
private bool Undelete(FolderItem Item)
{
try
{
foreach (FolderItemVerb FIVerb in Item.Verbs())
{
if (
(FIVerb.Name.ToUpper().Contains("WIEDERHERSTELLEN")) ||
(FIVerb.Name.ToUpper().Contains("ESTORE")) ||
(FIVerb.Name.ToUpper().Contains("NDELETE"))
)
{
FIVerb.DoIt();
return true;
}
}
//execute the first one:
Item.Verbs().Item(0).DoIt();
return true;
}
catch (Exception)
{
Debug.WriteLine("ERROR undeleting");
return false;
}
}
首先 - 對不起,剛剛完成大學,他們沒有在那裏教winapis ;-) 好的,所以我使用COM互操作。你說我需要參考互操作程序集。我想這是這裏的東西,這對我來說是相當小和好的:.. \ Visual Studio 2008 \ Projects \ Wing \ FileWing \ obj \ Debug \ Interop.Shell32.dll 現在我的問題是:我怎麼影響這個對象是在哪裏創建的(比如在其他地方設置這個對象的路徑),或者我怎麼可以在之前部署這個對象,所以它與我的應用程序一起安裝? – Akku 2010-01-25 16:37:02
@Tim,我不相信你可以影響它創建的位置。它由構建系統自動完成。要部署它,只需將其複製到應用程序的目標文件夾即可。 – JaredPar 2010-01-25 17:39:57
謝謝!這正是我需要做的:-) – Akku 2010-01-26 08:10:00