Solved

Deleting a key in registry

Posted on 1998-08-28
4
173 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now