Page 1 of 1 1
Topic Options
#19523 - 2002-04-04 05:49 PM Delete a value from the registry
jhdvy Offline
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. Offline
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 Offline
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

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#19526 - 2002-04-04 06:22 PM Re: Delete a value from the registry
jhdvy Offline
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#19528 - 2002-04-04 07:39 PM Re: Delete a value from the registry
Sealeopard Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2375 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.039 seconds in which 0.018 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org