IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Delphi Discussion :

Lire et écrire une clé binaire


Sujet :

Delphi

  1. #1
    Membre éprouvé Avatar de defluc
    Homme Profil pro
    Architecte
    Inscrit en
    Mai 2002
    Messages
    1 383
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 383
    Points : 1 199
    Points
    1 199
    Par défaut Lire et écrire une clé binaire
    Bonjour

    Je voudrais lire dans la base de registre, la clé Software\Microsoft\Office\9.0\Word\Data, sous HKEY_CURRENT_USER, qui contiendrait la liste des fichiers récents ouverts dans Ms-Word.

    NB : La sous-clé 9.0 dépend de la version de Word.

    Je ne vois pas comment déterminer la taille du buffer de l'instruction ReadBinaryData sans connaître le contenu de la clé.

    Quelqu'un pourrait-il m'aider ?


    Merci d'avance

  2. #2
    Expert éminent sénior
    Avatar de Jipété
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    10 933
    Détails du profil
    Informations personnelles :
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 10 933
    Points : 15 380
    Points
    15 380
    Par défaut
    Un jour j'ai trouvé ça sur le web :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    {Using Registry
    Several examples below shows how to use registry from your Delphi programs. While reading and writing simple data can be obvious, some other tasks can be difficult, especially for beginners. Here are some examples, which may help. 
    Reading Binary Data 
    Reading Entire Section 
    Writing Binary Data 
    Getting Subsection Information }
     
    //don't forget to put REGISTRY into your USES section. 
    //Reading Binary Data
    //The example below shows how to read binary data, which is usually shown in RegEdit as 20 00 00 00 from the registry. Later, you'll see how to write such data back to registry. 
     procedure TForm1.Button1Click(Sender: TObject);
     const
      Key  : String = '\Enum\Network\Family\0000\';
      Val  : String = 'Capabilities';
     var
      Data : Array of Byte;	// Dynamic Array - Delphi4 Only !!
      S    : String;
      sz   : Word;
      I    : Word;
     begin
      R := TRegistry.Create;
      with R do
       begin
     //
     // Set root key
     //
        RootKey := HKEY_LOCAL_MACHINE;
     //
     // Open Subkey
     //
        OpenKey(Key, False);
     //
     // If this is binary data
     //
        if GetDataType(Val) = rdBinary
         then
          begin
     //
     // Get the size
     //
           sz := GetDataSize(Val);
           if sz > 0 then
            begin
     //
     // Set the size of the dynamic array
     //
             SetLength(Data, sz);
     //
     // Read data into the array
     //
             ReadBinaryData(Val, Data[0], sz);
             S := Val + ' = ';
             for I := 0 to sz - 1 do
              begin
     //
     // Format 'em
     //
               S := S + Format('%2x',[Data[I]]);
              end;
     //
     // Show
     //
             Edit1.Text := S;
            end;
          end;
        Free;
       end;
     end;
     
    //Reading Entire Section
    //This example shows how to read the entire section without previous knowledge of the number of elements in it and its data types. 
     procedure TForm1.Button1Click(Sender: TObject);
     const
      Key  : String = '\Enum\Network\Family\0000\';
     var
      Data : Array of Byte;
      L    : TStringList;
      S    : String;
      sz   : Word;
      I,J  : Word;
     begin
      R := TRegistry.Create;
      L := TStringList.Create;
      with R do
       begin
    //
    // Set root key
    //
        RootKey := HKEY_LOCAL_MACHINE;
    //
    // Open subkey
    //
        OpenKey(Key, False);
    //
    // Get the list of keys
    //
        GetValueNames(L);
        If L.Count > 0 Then
         begin
          for I := 0 to L.Count - 1 do
           begin
    //
    // Get the data of the keys
    //
            case GetDataType(L[I]) of
    // String?
             rdString,
             rdExpandString :
               S := '"' + ReadString(L[I]) + '"';
    // Integer?
             rdInteger :
               S := IntToStr(ReadInteger(L[I]));
    // Binary?
             rdBinary :
              begin
               sz := GetDataSize(L[I]);
               SetLength(Data, sz);
               ReadBinaryData(L[I], Data[0], sz);
               S := '';
               for J := 0 to sz - 1 do
                begin
                 S := S + Format('%2x',[Data[J]]);
                end;
              end;
     // Unknown?
             rdUnknown :
              S := 'Unknown';
            end;
            Memo1.Lines.Add(L[I] + #9'' + S);
           end;
         end;
        Free;
       end;
      L.Free;
     end;
     
    //Writing Binary Data
    //This example shows how to write binary data to the registry. Here we use static array, but it can be dynamic also. 
     procedure TForm1.Button1Click(Sender: TObject);
     var
      B : Array [0..15] of Byte;
      I : Byte;
     Const
      SubKey  : String = 'Software\RegDemo';
     begin
      R := TRegistry.Create;
      with R do
       begin
     //
     // Set random data
     //
        for I := 0 to 15 do
         B[I] := Random(255);
     //
     // Create subkey
     //
        OpenKey(SubKey + '\BinKey', True);
     //
     // write binary data
     //
        WriteBinaryData('Value', B, SizeOf(B));
        Free;
       end;
     end;
     
    //Getting Subsection Information
    //The last example in this series. Here we get the information about the entire subkey - number of values, maximum length of the data and so on. This can be useful when you read the entire section into memory. 
     var
      R  : TRegistry;
      KI : TRegKeyInfo;
     const
      Key  : String = '\Enum\Network\Family\0000\';
     
     procedure TForm1.Button1Click(Sender: TObject);
     begin
      R := TRegistry.Create;
       with R do
       begin
     //
     // Set Root Key
     //
        RootKey := HKEY_LOCAL_MACHINE;
     //
     // Open Subkey
     //
        OpenKey(Key, False);
     //
        if GetKeyInfo(KI) then
         begin
          with KI do
           begin
            Memo1.Lines.Add(CurrentPath + #13#10);
            Memo1.Lines.Add('MaxSubKeyLen' + #9   +
             IntToStr(MaxSubKeyLen));
            Memo1.Lines.Add('NumValues'    + #9   +
             IntToStr(NumValues));
            Memo1.Lines.Add('MaxValueLen'  + #9   +
             IntToStr(MaxValueLen));
            Memo1.Lines.Add('MaxDataLen'   + #9   +
             IntToStr(MaxDataLen));
            Memo1.Lines.Add('FileTime'     + #9#9 +
             DateTimeToStr(FileTime.dwLowDateTime));
           end;
         end;
       end;
     end;
    Je m'en suis servi il y a qq années, c'est utilisable.
    --
    jp

Discussions similaires

  1. Lire et écrire une valeur binaire dans la base de registre
    Par DelphiCool dans le forum Codes sources à télécharger
    Réponses: 0
    Dernier message: 13/02/2013, 20h46
  2. [Débutant] Lire et écrire une structure
    Par Almenor dans le forum VB.NET
    Réponses: 2
    Dernier message: 23/09/2012, 22h18
  3. Réponses: 2
    Dernier message: 23/05/2008, 23h28
  4. [VB6] Lire et écrire sur une fenêtre dos...
    Par Zenar dans le forum VB 6 et antérieur
    Réponses: 14
    Dernier message: 16/03/2008, 13h14
  5. Comment écrire une adresse binaire
    Par jafo65 dans le forum C
    Réponses: 2
    Dernier message: 04/05/2006, 23h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo