?
Solved

Deleting a key in registry

Posted on 1998-08-28
4
Medium Priority
?
180 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 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

800 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