🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
11 messages
11 total messages Started by Fernando Alvarez Fri, 02 May 2003 23:10
Trying DeleteKey in the registry
#16644
Author: Fernando Alvarez
Date: Fri, 02 May 2003 23:10
17 lines
1311 bytes
Hi!

I'm trying to delete a key in the registry with DeleteKey but I don�t get to
do this job. I want to delete the key KAZAA and his value in the Run folder.

This is my code:

include <registry.hpp>

 TRegistry *registry = new TRegistry();
 registry->RootKey = HKEY_LOCAL_MACHINE;

registry->DeleteKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\KA
ZAA");
 delete registry;

Thank you.
Re: Trying DeleteKey in the registry
#16645
Author: Remy Lebeau (TeamB)
Date: Fri, 02 May 2003 23:16
13 lines
1244 bytes
"Fernando Alvarez" <ferjat@lycos.es> wrote in message
news:3eb2faf3$1@newsgroups.borland.com...

>
registry->DeleteKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\KA
ZAA");

What is the return value of DeleteKey()?  If false, what is the return value
of the Win32 API function GetLastError()?


Gambit
Re: Trying DeleteKey in the registry
#16646
Author: Fernando Alvarez
Date: Fri, 02 May 2003 23:37
35 lines
1762 bytes
How can I use GetLastError?
The return value of DeleteKey is 0. result=0;
The code now is:

  include <registry.hpp>
  int result;
    TRegistry *registry = new TRegistry();
    registry->RootKey = HKEY_LOCAL_MACHINE;

result=registry->DeleteKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\
Run\\KAZAA");
    delete registry;

Thank you Gambit.

"Remy Lebeau (TeamB)" <gambit47@yahoo.com> escribi� en el mensaje
news:3eb2fbdb$1@newsgroups.borland.com...
>
> "Fernando Alvarez" <ferjat@lycos.es> wrote in message
> news:3eb2faf3$1@newsgroups.borland.com...
>
> >
>
registry->DeleteKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\KA
> ZAA");
>
> What is the return value of DeleteKey()?  If false, what is the return
value
> of the Win32 API function GetLastError()?
>
>
> Gambit
>
>
>
Re: Trying DeleteKey in the registry
#16647
Author: Remy Lebeau (TeamB)
Date: Fri, 02 May 2003 23:45
14 lines
1352 bytes
"Fernando Alvarez" <ferjat@lycos.es> wrote in message
news:3eb30123@newsgroups.borland.com...
> How can I use GetLastError?

Just call it.  It is a global function:

    if(
!registry->DeleteKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\K
AZAA") )
        result = GetLastError();


Gambit
Re: Trying DeleteKey in the registry
#16648
Author: Fernando Alvarez
Date: Fri, 02 May 2003 23:51
21 lines
1523 bytes
Now result=5.

"Remy Lebeau (TeamB)" <gambit47@yahoo.com> escribi� en el mensaje
news:3eb302cb$1@newsgroups.borland.com...
>
> "Fernando Alvarez" <ferjat@lycos.es> wrote in message
> news:3eb30123@newsgroups.borland.com...
> > How can I use GetLastError?
>
> Just call it.  It is a global function:
>
>     if(
>
!registry->DeleteKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\K
> AZAA") )
>         result = GetLastError();
>
>
> Gambit
>
>
Re: Trying DeleteKey in the registry
#16649
Author: Remy Lebeau (TeamB)
Date: Sat, 03 May 2003 00:08
14 lines
1527 bytes
"Fernando Alvarez" <ferjat@lycos.es> wrote in message
news:3eb30488$1@newsgroups.borland.com...
> Now result=5.

As I thought, DeketeKey() is failing.  Error 5 is ERROR_ACCESS_DENIED.  In
other words, you tried to delete a key you don't have access to.

What OS are you trying this under?  If NT/Win2K/XP, are you trying to do
this under a user account with admin rights?  If not, then that is probably
why it is failing.


Gambit
Re: Trying DeleteKey in the registry
#16650
Author: Fernando Alvarez
Date: Sat, 03 May 2003 10:22
42 lines
2700 bytes
I am the administrator user in windows XP SP1. I have opened regedt32.exe
and I have all the permissions. I can delete, write, change, etc manually in
the registry. Then, I have done a test. I have wrotten a new key in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run with name
Hello and value nothing.
So, I have changed my code and it doesn�t work again. I am using BCB 5. This
is my code:

int result;
        TRegistry *registry = new TRegistry();
        registry->RootKey = HKEY_LOCAL_MACHINE;

if(!registry->DeleteKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run
\\Hello"))
                result = GetLastError();
        delete registry;

I think the problem is in DeleteKey. I might have to open the key and then
just delete it, or I dont�t know, to do something different. Any idea? Ah,
a last thing, the type of the key is REG_SZ. Is this important?

Thank you for your help.

"Remy Lebeau (TeamB)" <gambit47@yahoo.com> escribi� en el mensaje
news:3eb30813$1@newsgroups.borland.com...
>
> "Fernando Alvarez" <ferjat@lycos.es> wrote in message
> news:3eb30488$1@newsgroups.borland.com...
> > Now result=5.
>
> As I thought, DeketeKey() is failing.  Error 5 is ERROR_ACCESS_DENIED.  In
> other words, you tried to delete a key you don't have access to.
>
> What OS are you trying this under?  If NT/Win2K/XP, are you trying to do
> this under a user account with admin rights?  If not, then that is
probably
> why it is failing.
>
>
> Gambit
>
>
Re: Trying DeleteKey in the registry
#16651
Author: Chris
Date: Sat, 03 May 2003 11:29
40 lines
2140 bytes
"Fernando Alvarez" <ferjat@lycos.es> wrote in message
news:3eb39873@newsgroups.borland.com...
>if(!registry->DeleteKey("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Ru
n
\\Hello"))

Hi, I use the following as a function ;


bool DelRegKey(String KeyToOpen, String  KeyToDelete,void * RootKeyToOpen =
HKEY_CLASSES_ROOT);


bool DelRegKey(String  KeyToOpen, String KeyToDelete,void* RootKeyToOpen)
{
bool RetVal = false;
TRegistry *thisreg = new TRegistry;
try{
thisreg->RootKey = RootKeyToOpen;  //default if not supplied is
HKEY_CLASSES_ROOT

if (thisreg->OpenKey(KeyToOpen,false))
    {thisreg->DeleteKey(KeyToDelete);
     RetVal = true;}
else
    RetVal = false;
}
__finally
{
delete thisreg;
return RetVal;}
}


and then call it like this:
DelRegKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","Hello");

--- I have not tested this but it really ought to work

Chris
Re: Trying DeleteKey in the registry
#16652
Author: Chris
Date: Sat, 03 May 2003 11:42
5 lines
1329 bytes
DelRegKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","Hello",HKEY_L
OCAL_MACHINE);


Oops, slight correction, added HKEY_LOCAL_MACHINE to override default.
Re: Trying DeleteKey in the registry
#16653
Author: Nico Bendlin
Date: Sat, 03 May 2003 12:13
17 lines
1698 bytes
Fernando Alvarez wrote:
> Then, I have done a test. I have wrotten a new key in
> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
> with name Hello and value nothing.
> So, I have changed my code and it doesn�t work again.

a) 'Hello' is an value - not a key.

   So DeleteKey() is the wrong method.
   Open the key and delete the value.

b) You don't have KEY_ALL_ACCESS on the key.

   Specify only the required rights
   on creating the Registry object.

- nico
Re: Trying DeleteKey in the registry
#16656
Author: Fernando Alvarez
Date: Sat, 03 May 2003 17:29
28 lines
2183 bytes
Thank You Gambit, Thank You Chris and Thank You Nico Bendlin.

My error was that Kazaa and Hello isn?t a key , is a value, so I must use
DeleteValue. Now it works perfectly. I have seen your code Chris and it is
very interesting. I will use it.

Thank you very much.

"Nico Bendlin" <nicode@net.gmx> escribi� en el mensaje
news:3eb3b192@newsgroups.borland.com...
> Fernando Alvarez wrote:
> > Then, I have done a test. I have wrotten a new key in
> > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
> > with name Hello and value nothing.
> > So, I have changed my code and it doesn�t work again.
>
> a) 'Hello' is an value - not a key.
>
>    So DeleteKey() is the wrong method.
>    Open the key and delete the value.
>
> b) You don't have KEY_ALL_ACCESS on the key.
>
>    Specify only the required rights
>    on creating the Registry object.
>
> - nico
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads