+ 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
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196

    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,110
    Blog Entries
    2
    Thank Post
    110
    Thanked 511 Times in 443 Posts
    Rep Power
    114

  3. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196
    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,326
    Thank Post
    82
    Thanked 386 Times in 257 Posts
    Rep Power
    106

  5. #5

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,003
    Thank Post
    192
    Thanked 413 Times in 300 Posts
    Rep Power
    136
    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
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196
    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,003
    Thank Post
    192
    Thanked 413 Times in 300 Posts
    Rep Power
    136
    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,110
    Blog Entries
    2
    Thank Post
    110
    Thanked 511 Times in 443 Posts
    Rep Power
    114
    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. vb script to delete sub folders
    By ful56_uk in forum Scripts
    Replies: 1
    Last Post: 30th April 2010, 10:46 PM
  2. Script a changing of the owner on regkeys?
    By MicrodigitUK in forum Scripts
    Replies: 4
    Last Post: 3rd December 2008, 02:05 PM
  3. VB script to delete certain folders
    By PTD in forum Scripts
    Replies: 7
    Last Post: 4th June 2008, 12:30 PM
  4. need a script to delete shortcuts
    By philtomo-25 in forum Scripts
    Replies: 2
    Last Post: 1st November 2007, 04:50 PM
  5. Script to Delete Profiles - PLEASE HELP
    By Mr_M_Cox in forum Scripts
    Replies: 10
    Last Post: 13th June 2007, 03:51 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
  •