Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.12.10;
Скачать: CL | DM;

Вниз

Поиск по реестру   Найти похожие ветки 

 
Destroyer ©   (2006-07-30 17:20) [0]

Нужно найти в реестре в указанном пути определенные значения (как имена ключей, так и имена разделов(обозначаются значком папки в regedit-е)). Функции типа FindFirst\FindNext не нашел. Как осуществить такой поиск?


 
Шпиён   (2006-07-30 17:58) [1]


> Функции типа FindFirst\FindNext не нашел.

RegEnumKeyEx ?


 
Destroyer ©   (2006-07-30 20:20) [2]


> RegEnumKeyEx ?

Точно, вроде то, что нужно. А есть готовый алгоритм поиска? Просто тут накидываю, но что-то тяжело\медленно идет.


 
Destroyer ©   (2006-07-30 21:24) [3]

Вот что удалось сделать, но чувствую можно подправить этот код + он перечисляет то, что находится в HKEY_CURRENT_USER, а нужно зайти глубоко в дерево ключей и там поискать нужные (не все же перебирать).


var

i           : integer;
ftime       : PFileTime;
h_Key       : hKey;
RegRes      : integer;
BufferSize  : Cardinal;
buf         : array[0..MAX_PATH] of char;

begin
 h_Key:=HKEY_CURRENT_USER;
 i:=0;
 BufferSize:= SizeOf(buf);
 RegRes:=RegEnumKeyEx(h_Key,i,@buf,BufferSize,nil,nil,nil,nil);
 while RegRes = ERROR_SUCCESS do
  begin
   BufferSize:= SizeOf(buf);
   inc(i);
   RegRes:=RegEnumKeyEx(h_Key,i,@buf,BufferSize,nil,nil,nil,ftime);
  end;

 reg.CloseKey;
 reg.Free;

 end;


 
Шпиён   (2006-07-30 21:58) [4]

Platform SDK: Windows System Information
Enumerating Registry Subkeys
The following example uses the RegQueryInfoKey, RegEnumKeyEx, and RegEnumValue functions to enumerate the subkeys of the specified key. The hKey parameter passed to each function is a handle to an open key. This key must be opened before the function call and closed afterward.



// QueryKey - Enumerates the subkeys of key and its associated values.
//     hKey - Key whose subkeys and values are to be enumerated.

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383

void QueryKey(HKEY hKey)
{
   TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
   DWORD    cbName;                   // size of name string
   TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name
   DWORD    cchClassName = MAX_PATH;  // size of class string
   DWORD    cSubKeys=0;               // number of subkeys
   DWORD    cbMaxSubKey;              // longest subkey size
   DWORD    cchMaxClass;              // longest class string
   DWORD    cValues;              // number of values for key
   DWORD    cchMaxValue;          // longest value name
   DWORD    cbMaxValueData;       // longest value data
   DWORD    cbSecurityDescriptor; // size of security descriptor
   FILETIME ftLastWriteTime;      // last write time

   DWORD i, retCode;

   TCHAR  achValue[MAX_VALUE_NAME];
   DWORD cchValue = MAX_VALUE_NAME;

   // Get the class name and the value count.
   retCode = RegQueryInfoKey(
       hKey,                    // key handle
       achClass,                // buffer for class name
       &cchClassName,           // size of class string
       NULL,                    // reserved
       &cSubKeys,               // number of subkeys
       &cbMaxSubKey,            // longest subkey size
       &cchMaxClass,            // longest class string
       &cValues,                // number of values for this key
       &cchMaxValue,            // longest value name
       &cbMaxValueData,         // longest value data
       &cbSecurityDescriptor,   // security descriptor
       &ftLastWriteTime);       // last write time

   // Enumerate the subkeys, until RegEnumKeyEx fails.
   
   if (cSubKeys)
   {
       printf( "\nNumber of subkeys: %d\n", cSubKeys);

       for (i=0; i<cSubKeys; i++)
       {
           cbName = MAX_KEY_LENGTH;
           retCode = RegEnumKeyEx(hKey, i,
                    achKey,
                    &cbName,
                    NULL,
                    NULL,
                    NULL,
                    &ftLastWriteTime);
           if (retCode == ERROR_SUCCESS)
           {
               _tprintf(TEXT("(%d) %s\n"), i+1, achKey);
           }
       }
   }

   // Enumerate the key values.

   if (cValues)
   {
       printf( "\nNumber of values: %d\n", cValues);

       for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
       {
           cchValue = MAX_VALUE_NAME;
           achValue[0] = "\0";
           retCode = RegEnumValue(hKey, i,
               achValue,
               &cchValue,
               NULL,
               NULL,
               NULL,
               NULL);

           if (retCode == ERROR_SUCCESS )
           {
               _tprintf(TEXT("(%d) %s\n"), i+1, achValue);
           }
       }
   }
}

void _tmain(void)
{
  HKEY hTestKey;

  if( RegOpenKeyEx( HKEY_CURRENT_USER,
       TEXT("SOFTWARE\\Microsoft"),
       0,
       KEY_READ,
       &hTestKey) == ERROR_SUCCESS
     )
  {
     QueryKey(hTestKey);
  }
}


 
Destroyer ©   (2006-07-31 12:09) [5]

Спасибо



Страницы: 1 вся ветка

Текущий архив: 2006.12.10;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.048 c
15-1164203150
Oleg Babenko
2006-11-22 16:45
2006.12.10
Нахождения нужной суммы из массива сумм


2-1164224668
Romal
2006-11-22 22:44
2006.12.10
что быстрее?


15-1163881631
Alexis
2006-11-18 23:27
2006.12.10
Windows.pas из установки Delphi7


2-1164350708
r9000
2006-11-24 09:45
2006.12.10
Перевод строки в дату.


2-1163930968
Max.66RUS
2006-11-19 13:09
2006.12.10
Вопрос по буферу обмена...