Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Function to Delete a Registry Key

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,35248
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Function to Delete a Registry Key
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Function to Delete a Registry Key - 6/8/2006 7:41:40 AM   
  DiGiTAL.SkReAM


Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
PLEASE BE EXTREMELY CAREFUL WHEN USING THIS FUNCTION
I ASSUME NO RESPONSIBILITY IF YOU DELETE HALF OF YOUR
REGISTRY AND LOSE ALL OF YOUR WINDOWS FUNCTIONALITY!!!!!
AS ALWAYS, BACKUP YOUR REGISTRY BEFORE USING THIS FUNCTION!!!!!




This function will delete the registry key passed to it.
It will also delete any subkeys and values.
Returns a 0 if successfull, or a 1 if errors occur.

To use the function, place it in your script, and call it with the full path to the key that you want to delete as the first parameter, and the word "DELETE" (yes, it must be in all caps) as the second parameter.  This to prevent an accidental reference to the function from totally hosing your box.




      

< Message edited by DiGiTAL.SkReAM -- 6/8/2006 7:56:37 AM >


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury
 
 
Revisions: 1 | Post #: 1
 
 RE: Function to Delete a Registry Key - 6/1/2007 6:04:43 AM   
  DiGiTAL.SkReAM


Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Apparently, Microsoft has released an update that breaks this functionality when used in this way.  I am not sure which update it was, but I am seeing this work on some computers that have not updated in a few months, but it doesn't delete keys with subkeys on computers that HAVE updated recently.

So.

The only reliable way I have found as of yet to delete a key and any/all of its subkeys and values, is you have to write a reg file that will delete the key you select.
For example:

Windows Registry Editor Version 5.00

[-HKEY_LOCAL_MACHINE\SYSTEM\Mykey]

and then run it with a regedit /s file.reg

I will post a complete function to do this when time allows, but I wanted to get this up here so that maybe someone else can address this before I have to. heheheh

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 2
 
 RE: Function to Delete a Registry Key - 6/2/2007 12:20:22 AM   
  dm_4ever


Posts: 2432
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
I tried your function and it did not work for me until I changed this line.

From:
fKillRegKey sKeyRoot & "\" & sKeyToKill & "\" & sSubKey, "DELETE"

To:  
fKillRegKey strKeyRoot & "\" & sKeyToKill & "\" & sSubKey, "DELETE"

NOTE: Using WinXP Pro SP2 with all the latest patches


The following is based off your original and uses the other method you suggested with the .reg file.


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 3
 
 RE: Function to Delete a Registry Key - 6/3/2007 2:13:24 PM   
  DiGiTAL.SkReAM


Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Yes, I did have that typo in there.  However, I have noticed, that like so many things with WMI, that this function is not reliable.  It works most of the time, but occasionally fails to delete the key if subkeys exist.  Not all the time, but just enough to drive me stark raving mad.

Thanks for the code.  I have my own, but I have "optimized" it to work with my includes file, so it references a few of my own functions that I have just been too lazy to recode here.

Note:  On Windows NT, etc. the first line needs to be REGEDIT4 and there should be no space between this line and the keyname:
REGEDIT4
[-keyname]



_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to dm_4ever)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Function to Delete a Registry Key Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts