Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

RegKeyDelete & SubKeys [Delphi, Windows]


_Simon_ ©   (2005-11-30 19:13:00) 


В KOL нет аналога функции:
function DeleteKey(const Key: String): Boolean;

Финкция из KOL


//[function RegKeyDelete]
function RegKeyDelete( Key: HKey; const SubKey: String ): Boolean;
begin
 Result := FALSE;
 if Key <> 0 then
   Result := RegDeleteKey( Key, PChar( SubKey ) ) = ERROR_SUCCESS;
end;


использует RegDeleteKey которая:
Windows NT: The RegDeleteKey function deletes the specified key.
This function cannot deletea key that has subkeys.

В Win32 SDK Delphi 7 ничего другого не нашел.
Написал следующее:


function RegKeyDeleteFull(Key: HKey; const SubKey: PChar): Boolean;
var
 List: PStrList;
 NewKey: HKey;
 i, count: Longint;
begin
 if Key <> 0 then
   begin
     NewKey:=RegAPIOpen(Key, SubKey, False);
     List:=NewStrList;
     RegKeyGetSubKeys(NewKey, List);
     count:=List.Count;
     if count = 0 then
       Result := RegDeleteKey(Key, SubKey) = ERROR_SUCCESS
     else {if count>0}
       begin
         for i:=0 to count-1 do
           RegAPIKeyDelete(NewKey, List.ItemPtrs[i]);
           //RegAPIClose(NewKey, List.ItemPtrs[i]);
       end;
     List.Free;
     RegKeyClose(NewKey);
   end {if Key <> 0}
  else
    Result := FALSE;
end;


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


Thaddy   (2005-12-02 15:26:00) [1]

Yes, that works very good, but remember: make a back up of the keys you delete! it is dangerous to delete keys and it is easy to make a mistake. The registry differs between OS versions and even between SP's


_Simon_   (2005-12-01 20:14:00) [2]

Все это хорошо, но это лучше:

...
function SHDeleteKey(Key: HKey; const SubKey: PChar): LongInt; stdcall;

implementation

function SHDeleteKey; external 'shlwapi.dll' name 'SHDeleteKeyA';
...


Но трбует IE 4.0 (Уже практически не актуально).


thaddy   (2005-11-30 20:42:00) [3]

Note that kolexregistry uses err.pas, so it will grow your code a bit.
But you can study the delete method from kolregistry.pas and apply that to your code. Or simply use kolregistry with USE_ERR undefined.

Deleting keys is dangerous! and can destroy a windows installation totally!

Deleting keys should always be done with a backup, that's why I wrote KolExregistry.


MTsv DN   (2005-11-30 19:44:00) [4]

Привет...
Посмотри:
http://members.chello.nl/t.koning8/kolexregistry.zip
http://www.uus4u.com/download/modules/KOLnMCK/kol_registry.zip- это у меня.

Но это НЕ портированный registry.pas из Delphi в KOL. Я просто избавился от всех uses'ов которые увеличивали размер... Это я к тому, что пользоваться ее надо, как родной Delph'овой...

var
reg : TRegistry
begin
reg := TRegistry.Create(nil);

и т.д.

Переводил ОЧЕНЬ давно...тогда для моих нужд хватило и этого... А сейчас лень править :о)...

Вообще, рекомендую kolexregistry.zip

С Уважением MTsv DN


Наверх

Титульная страница Поиск, карта сайта Написать письмо