code_junkie

How can I tell that a directory is really a recycle bin?

Nov 10th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <windows.h>
  2. #include <shlobj.h>
  3. #include <tchar.h>
  4. #include <stdio.h>
  5.  
  6. HRESULT GetFolderDescriptionId(LPCWSTR pszPath, SHDESCRIPTIONID *pdid)
  7. {
  8. HRESULT hr;
  9. LPITEMIDLIST pidl;
  10. if (SUCCEEDED(hr = SHParseDisplayName(pszPath, NULL,&pidl, 0, NULL))) {
  11. IShellFolder *psf;
  12. LPCITEMIDLIST pidlChild;
  13. if (SUCCEEDED(hr = SHBindToParent(pidl, IID_IShellFolder, (void**)&psf, &pidlChild))) {
  14. hr = SHGetDataFromIDList(psf, pidlChild,SHGDFIL_DESCRIPTIONID, pdid, sizeof(*pdid));
  15. psf->Release();
  16. }
  17. CoTaskMemFree(pidl);
  18. }
  19. return hr;
  20. }
  21.  
  22. int __cdecl wmain(int argc, WCHAR **argv)
  23. {
  24. SHDESCRIPTIONID did;
  25. if (SUCCEEDED(GetFolderDescriptionId(argv[1], &did)) && did.clsid == CLSID_RecycleBin) {
  26. printf("is a recycle binn");
  27. } else {
  28. printf("is not a recycle binn");
  29. }
  30. return 0;
  31. }
  32.  
  33. C:> checkrecycle C:Windows
  34. is not a recycle bin
  35. C:> checkrecycle C:RECYCLERS-1-5-21-2127521184-1604012920-1887927527-72713
  36. is a recycle bin
Add Comment
Please, Sign In to add comment