#19523 - 2002-04-04 05:49 PM
Delete a value from the registry
|
jhdvy
Fresh Scripter
Registered: 2002-03-22
Posts: 44
Loc: New Jersey
|
I need to delete a value from the registry. I know something is wrong with my first line because the value is not a key. The second line works fine. Thanks
if existkey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , "RealTRay" DelValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , "RealTray") endif
|
|
Top
|
|
|
|
#19524 - 2002-04-04 06:06 PM
Re: Delete a value from the registry
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Try this:
code:
$RealTray=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , "RealTray") if $RealTray<>"" DelValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","RealTray") endif
|
|
Top
|
|
|
|
#19525 - 2002-04-04 06:12 PM
Re: Delete a value from the registry
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The value could be NULL. I think that using @error may be more sound. code:
$RealTray=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , "RealTray") if @error = 0 DelValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","RealTray") endif
|
|
Top
|
|
|
|
#19526 - 2002-04-04 06:22 PM
Re: Delete a value from the registry
|
jhdvy
Fresh Scripter
Registered: 2002-03-22
Posts: 44
Loc: New Jersey
|
Thanks. It worked but it returns a value of 0 in the dos box. Can I get rid of that? Thanks for your help. I'm new at this.
|
|
Top
|
|
|
|
#19527 - 2002-04-04 06:24 PM
Re: Delete a value from the registry
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Use a variable to catch the return value from DelValue().
$rc = DelValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","RealTray") [ 04 April 2002, 18:24: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#19528 - 2002-04-04 07:39 PM
Re: Delete a value from the registry
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
You didn't close the EXISTKEY command, also KEYEXIST has replaced EXISTKEY and should not be used anymore. Try this:
code:
if KeyExist('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run','RealTRay') $retcode=DelValue('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run','RealTray') endif
Oh, and if that still doesn't work, then check the permissions on the registry key. By default, changes to the HKEY_LOCAL_MACHINE registry area require administrative privileges. You should also check the HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run registry keys [ 04 April 2002, 19:41: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1894 anonymous users online.
|
|
|