Solved

Deleting a key in registry

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

13 Experts available now in Live!

Get 1:1 Help Now