+ Post New Thread
Results 1 to 8 of 8
Scripts Thread, Script to Delete RegKeys in Coding and Web Development; Hi, Does anyone have a simple script that will delete all keys (folders) in the below registry location please? HKEY_LOCAL_MACHINE\System\CurentControlSet\Control ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,957
    Thank Post
    886
    Thanked 1,700 Times in 1,477 Posts
    Blog Entries
    12
    Rep Power
    448

    Script to Delete RegKeys

    Hi,

    Does anyone have a simple script that will delete all keys (folders) in the below registry location please?

    HKEY_LOCAL_MACHINE\System\CurentControlSet\Control \Print\Connections\

    Thank You

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124

  3. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,957
    Thank Post
    886
    Thanked 1,700 Times in 1,477 Posts
    Blog Entries
    12
    Rep Power
    448
    Sorry i missed some out

    I would like a script that will delete all keys in the above area but only when a server replies to a ping.

    Also i dont want the connections key deleting just the ones under that.

    Sorry to mess you around

    Thanks
    Last edited by FN-GM; 26th August 2010 at 09:34 PM.

  4. #4
    somabc's Avatar
    Join Date
    Oct 2007
    Location
    London
    Posts
    2,337
    Thank Post
    83
    Thanked 388 Times in 258 Posts
    Rep Power
    111

  5. #5

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,055
    Thank Post
    209
    Thanked 429 Times in 309 Posts
    Rep Power
    144
    As an alturnative to a ping, which I never got working properly in VB script for some reason, create a single hidden read only share on the server with just a txt file in it, then you can simply use an "if file exists" statement with the full UNC path to see if the script can see the share, and thus the server - I use this to determine whether a member of staffs laptop is on the school network or not when they logon, and thus change the proxy settings accordingly.

    Mike.
    Last edited by maniac; 27th August 2010 at 12:18 AM.

  6. #6

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,957
    Thank Post
    886
    Thanked 1,700 Times in 1,477 Posts
    Blog Entries
    12
    Rep Power
    448
    Hi,

    For now i am using the below script to delete the subkeys only. But it doesnt work. Can anyone see why please?

    Thanks

    Code:
    On Error Resume Next 
    
    Const HKEY_LOCAL_MACHINE = &H80000001 
    
    strComputer = "."
    strKeyPath = "SYSTEM\CurrentControlSet\Control\Print\Connections" 
    
    Set objRegistry = GetObject("winmgmts:\\" & _
        strComputer & "\root\default:StdRegProv") 
    
    DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath 
    
    Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath) 
        objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys 
    
        If IsArray(arrSubkeys) Then 
            For Each strSubkey In arrSubkeys 
                DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey 
            Next 
        End If 
    
    '    objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath 
    End Sub

  7. #7

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,055
    Thank Post
    209
    Thanked 429 Times in 309 Posts
    Rep Power
    144
    Have you taken the 'on error resume next' statement out and seen what errors it produces?

  8. #8

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    It doesn't work because you've commented out the line which makes it work ...

    What it's doing is recursively calling the DeleteSubkeys routine and you need that last line otherwise it won't delete the low level keys.

    I think you could do:

    Code:
    if strKeyPath<>"SYSTEM\CurrentControlSet\Control\Print\Connections" then 
        objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath 
    end if
    but try this on a sacrificial machine first!

SHARE:
+ Post New Thread

Similar Threads

  1. Script to Delete Profiles - PLEASE HELP
    By Mr_M_Cox in forum Scripts
    Replies: 13
    Last Post: 22nd February 2013, 03:53 PM
  2. vb script to delete sub folders
    By ful56_uk in forum Scripts
    Replies: 1
    Last Post: 30th April 2010, 10:46 PM
  3. Script a changing of the owner on regkeys?
    By MicrodigitUK in forum Scripts
    Replies: 4
    Last Post: 3rd December 2008, 01:05 PM
  4. VB script to delete certain folders
    By PTD in forum Scripts
    Replies: 7
    Last Post: 4th June 2008, 12:30 PM
  5. need a script to delete shortcuts
    By philtomo-25 in forum Scripts
    Replies: 2
    Last Post: 1st November 2007, 03:50 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •