home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri K-CD 2002 #1 / K-CD_2002-01.iso / Delphi / INFO / Extras / RegCleanUtility / Source / D6RegClean.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-22  |  1.7 KB  |  75 lines

  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #include <Registry.hpp>
  5. #include "D6RegClean.h"
  6.  
  7. #pragma hdrstop
  8. USEFORM("Unit1.cpp", Form1);
  9. USEFORM("Unit2.cpp", Form2);
  10. USERC("D6RegClean.rc");
  11. USERC("Unit1.rc");
  12. USERC("unit2.rc");
  13. USERES("D6RegClean.res");
  14. //---------------------------------------------------------------------------
  15. TRegClean *Cleanup;
  16.  
  17. //---------------------------------------------------------------------------
  18. WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  19. {
  20.     Cleanup = new TRegClean;
  21.  
  22.     try
  23.     {
  24.          Application->Initialize();
  25.          Application->CreateForm(__classid(TForm1), &Form1);
  26.          Application->CreateForm(__classid(TForm2), &Form2);
  27.          Application->Run();
  28. //         }
  29.     }
  30.     catch (Exception &exception)
  31.     {
  32.          Application->ShowException(&exception);
  33.     }
  34.  
  35.     delete Cleanup;
  36.     return 0;
  37. }
  38. //---------------------------------------------------------------------------
  39.  
  40. __fastcall TRegClean::TRegClean()
  41. {
  42.     Reg = new TRegistry;
  43.     Reg->RootKey = HKEY_CURRENT_USER;
  44. }
  45.  
  46. __fastcall TRegClean::~TRegClean()
  47. {
  48.     delete Reg;
  49. }
  50.  
  51. int TRegClean::RemoveKey(String szKey)
  52. {
  53.     int nResult = SUCCESS;
  54.  
  55.     Reg->Access = KEY_ALL_ACCESS;
  56.  
  57.     if (Reg->OpenKey(szKey, false)) {
  58.         try {
  59.             if (Reg->DeleteKey(szKey)) {
  60.                 nResult = SUCCESS;
  61.             } else {
  62.                 nResult = FAILURE;
  63.             }
  64.         } catch (...) {
  65.             nResult = FAILURE;
  66.         }
  67.         Reg->CloseKey();
  68.     }
  69.     return nResult;
  70. }
  71.  
  72. //---------------------------------------------------------------------------
  73.  
  74.  
  75.