开发者

I can not remove a Registry key in code from Delphi

Win7x64, DelphiXe. Has written the program, which registers the control panel applet (as here recommend: http://msdn.microsoft.com/en-us/library/bb757044.aspx). All perfectly works, the applet is normally registered, displayed and started.

But at removal of a key of the register where it is registered:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\{0052D9FC-6764-4D29-A66F-2F3BD9E2BB40}

occurs nothing:

Create:

...
var reg1:tregistry;key:string;
begin
key:='SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\ {0052D9FC-6764-4D29-A66F-2F3BD9E2BB40}';
reg1:=tregistry.Create;
reg1.RootKey:=HKEY_LOCAL_MACHINE;
reg1.Access: = KEY_WOW64_64KEY + KEY_ALL_ACCESS;
if reg1.Openkey(key,true)=true then showmessage('ok');
reg1.Closekey;
reg1.free;
end;

Delete:

procedure TForm1.Button1Click (Sender: TObject);
    var reg1:tregistry; key:string;
    begin
    reg1: = tregistry.Create;
    reg1.RootKey: = HKEY_LOCAL_MACHINE;
    reg1.Access: = KEY_WOW64_64KEY + KEY_ALL_ACCESS;
    key: ='SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\{0开发者_如何转开发052D9FC-6764-4D29-A66F-2F3BD9E2BB40}';
    if reg1.KeyExists (Key)=true then Showmesage ('Key exists'); // work
    if reg1.DeleteKey (Key)=true then Showmesage ('Ok'); // ! not work !
    Showmesage (inttostr(getlasterror)); // show "0"
    reg1.Free;
    end;

Errors any does not stand out, but the key does not leave. The program is started from under the accounting record of the admin (+ creates this key too it). Through Regedit.exe a key it is visible and it is possible to remove.

What can stir to removal? :(


Try this:

IF reg1.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace') THEN TRY
  reg1.DeleteKey('{0052D9FC-6764-4D29-A66F-2F3BD9E2BB40}')
FINALLY
  reg1.CloseKey
END;

Also make sure that there are no sub keys under this key. If there are, you'll need to explicitly delete these sub keys before you can delete the parent key.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜