Solved

Deleting a key in registry

Posted on 1998-08-28
4
179 Views
Last Modified: 2010-04-04
I'm have trouble deleting a key from the registry -> setting the key goes OK - The deleting goes fine too, but the key remains...
Heres the code:

Var
DelKey:pchar;

begin
  OVI.dwOSVersionInfoSize := SizeOf(OVI);
  GetVersionEx(OVI);
  case OVI.dwPlatformID of
       VER_PLATFORM_WIN32_WINDOWS :
          CurVerKey := '\SOFTWARE\Microsoft\Windows\CurrentVersion\Run';
       VER_PLATFORM_WIN32_NT      :
          CurVerKey := '\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Run';
  else
      CurVerKey := '';
  end;

DelKey:='AppLauncher';

      with TRegistry.Create do
        try
          RootKey := HKEY_LOCAL_MACHINE;
          if OpenKey(CurVerKey, False) then
             DeleteKey(DelKey);
          CloseKey;
        finally
          Free;
         End;

Why doesn't this remove the key??

I have checked the spelling many times..

0
Comment
Question by:sancolumbusdk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 1337961
sancolumbusdk,

don't know why it doesn't work. I don't like the delphi TRegistry object at all. Try my winAPI function:

function RegDelKey(key: HKEY; const path: string) : boolean;
var c2 : cardinal;
begin
  result:=false;
  c2:=RegDeleteKey(key,PChar(path));
  if (c2<>ERROR_SUCCESS) and (c2<>2) then
    Application.MessageBox(PChar('Error number: '+IntToStr(c2)),PChar('Deleting RegKey "'+path+'"'),0);
  result:=c2=ERROR_SUCCESS;
end;
0
 

Author Comment

by:sancolumbusdk
ID: 1337962
Seems interesting vil try it monday :-)
0
 

Author Comment

by:sancolumbusdk
ID: 1337963
I've checked the routine, and it lead me to another conclusion. My routine doesn't work because I'm trying to delete key when it is a Value I want to remove. So I used the wrong method.

Your function works too if it is used for deleting keys - not values..


0
 
LVL 20

Expert Comment

by:Madshi
ID: 1337964
That's right...   :-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question