Jump to content

[C] Get status and empty recycle bin

- - - - -

  • Please log in to reply
No replies to this topic

#1
jakash3

jakash3

    Newbie

  • Members
  • PipPip
  • 21 posts
Made this command-line tool a while ago.
Can get the size in bytes + count of items in recycle bin or empty it.
It works by calling SHQueryRecycleBin and SHEmptyRecycleBin from Shellapi.h which is derived from shell32.dll
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <Shellapi.h>

void help() {
   printf(
      "rbin - by Jakash3\n"
      "Empties or queries information about the Recycle Bin\n"
      "Usage: rbin (info | empty (-d | -p | -s))\n"
      "info   Output size in bytes and number of items in recycle bin\n"
      "empty  Empty the recycle bin {\n"
      "          -d   Show confirmation dialog box\n"
      "          -p   Show progress dialog\n"
      "          -s   Play sound when complete\n"
      "       }\n"
   );
}

int main(int argc, char *argv[]) {
   if (argc <= 1) { help(); return 1; }
   if (!strcmp(argv[1], "info")) {
      SHQUERYRBINFO binfo;
      binfo.cbSize = sizeof(SHQUERYRBINFO);
      HRESULT res = SHQueryRecycleBin(0, &binfo);
      if (res == S_OK) {
         printf(
            "Bytes:%I64d\n"
            "Count:%I64d\n",
            binfo.i64Size,
            binfo.i64NumItems
         );
      } else {
         printf("Error getting recycle bin information.\n");
      }
   } else if (!strcmp(argv[1],"empty")) {
      int dwFlags = SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND;
      int i;
      for (i=0; i<argc; i++) {
         if (i >= 2) {
            if (!strcmp(argv[i], "-d")) {
               dwFlags = dwFlags ^ SHERB_NOCONFIRMATION;
            } else if (!strcmp(argv[i], "-p")) {
               dwFlags = dwFlags ^ SHERB_NOPROGRESSUI;
            } else if (!strcmp(argv[i], "-s")) {
               dwFlags = dwFlags ^ SHERB_NOSOUND;
            }
         }
      }
      SHEmptyRecycleBin(0, 0, dwFlags);
   } else {
      help();
      return 1;
   }
    return 0;
}

Posted Image
Posted Image




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users