Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. void __fastcall TForm2::InsertToRegBtnClick(TObject *Sender)
  2. {
  3.     TRegistry* reg = new TRegistry(KEY_READ);
  4.     reg->RootKey = HKEY_LOCAL_MACHINE;
  5.  
  6.     if(!reg->KeyExists("Software\\MyCompanyName\\MyApplication\\"))
  7.     {
  8.         MessageDlg("Key not found! Created now.",
  9.                     mtInformation, TMsgDlgButtons() << mbOK, 0);
  10.     }
  11.     reg->Access = KEY_WRITE;
  12.     bool openResult = reg->OpenKey("Software\\MyCompanyName\\MyApplication\\", true);
  13.  
  14.     if(!openResult)
  15.     {
  16.         MessageDlg("Unable to create key! Exiting.",
  17.                     mtError, TMsgDlgButtons() << mbOK, 0);
  18.         return;
  19.     }
  20.     //Checking if the values exist and inserting when neccesary
  21.  
  22.     if(!reg->KeyExists("Creation\ Date"))
  23.     {
  24.         TDateTime today = TDateTime::CurrentDateTime();
  25.         reg->WriteDateTime("Creation\ Date", today);
  26.     }
  27.  
  28.     if(!reg->KeyExists("Licenced\ To"))
  29.     {
  30.         reg->WriteString("Licenced\ To", "MySurname\ MyFirstName");
  31.     }
  32.  
  33.     if(!reg->KeyExists("App\ Location"))
  34.     {
  35.         reg->WriteExpandString("App\ Location",
  36.                                 "%PROGRAMFILES%\\MyCompanyName\\MyApplication\\");
  37.     }
  38.  
  39.     if(!reg->KeyExists("Projects\ Location"))
  40.     {
  41.         reg->WriteExpandString("Projects\ Location",
  42.                                 "%USERPROFILE%\\MyApplication\\Projects\\");
  43.     }
  44.  
  45.     reg->CloseKey();
  46.     reg->Free();
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TForm2::DelFromRegBtnClick(TObject *Sender)
  50. {
  51.     //Deleting the example registry entries
  52.     TRegistry* reg = new TRegistry(KEY_WRITE);
  53.     reg->RootKey = HKEY_LOCAL_MACHINE;
  54.  
  55.     reg->DeleteKey("Software\\MyCompanyName\\MyApplication");
  56.     reg->DeleteKey("Software\\MyCompanyName");
  57.  
  58.     reg->CloseKey();
  59.     reg->Free();
  60. }
  61. //---------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment