Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 610
  • Last Modified:

Delete Value and keys from the Registry using VBscript

I need to delete registry key and subkeys. Could someone help me with a vbscript that would do that. The folder I am trying to delete is
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Digest folder and its contents.

I--New-Folder--2--untitled2.bmp
0
Vicki05
Asked:
Vicki05
  • 9
  • 7
1 Solution
 
becraigCommented:
Here  is a good script for this:

On Error Resume Next 

Const HKEY_CURRENT_USER = &H80000001 

strComputer = "."
strKeyPath = "Software\Test" 

Set objRegistry = GetObject("winmgmts:\\" & _
    strComputer & "\root\default:StdRegProv") 

DeleteSubkeys HKEY_CURRENT_USER, strKeypath 

Sub DeleteSubkeys(HKEY_CURRENT_USER, strKeyPath) 
    objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys 

    If IsArray(arrSubkeys) Then 
        For Each strSubkey In arrSubkeys 
            DeleteSubkeys HKEY_CURRENT_USER, strKeyPath & "\" & strSubkey 
        Next 
    End If 

    objRegistry.DeleteKey HKEY_CURRENT_USER, strKeyPath 
End Sub

Open in new window


The concept is, it deletes each subkey first before deleting the key you want to have removed.

I did take this from technet.
http://technet.microsoft.com/en-us/magazine/2006.08.scriptingguy.aspx
0
 
Vicki05Author Commented:
I tried that but it does not seem to work.

On Error Resume Next

Const HKU = &H80000003

strComputer = "."
strKeyPath = "\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Digest"

Set objRegistry = GetObject("winmgmts:\\" & _
    strComputer & "\root\default:StdRegProv")

DeleteSubkeys HKU, strKeypath

Sub DeleteSubkeys(HKU, strKeyPath)
    objRegistry.EnumKey HKU, strKeyPath, arrSubkeys

    If IsArray(arrSubkeys) Then
        For Each strSubkey In arrSubkeys
            DeleteSubkeys HKU, strKeyPath & "\" & strSubkey
        Next
    End If

    objRegistry.DeleteKey HKU, strKeyPath
End Sub



msgbox "Done"
0
 
becraigCommented:
ok so it looks like you missed the full path for the reg key.

On Error Resume Next 

Const HKEY_USERS = &H80000003

strComputer = "."
strKeyPath = ".DEFAULT\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Digest" 

Set objRegistry = GetObject("winmgmts:\\" & _
    strComputer & "\root\default:StdRegProv") 

DeleteSubkeys HKEY_USERS, strKeypath 

Sub DeleteSubkeys(HKEY_USERS, strKeyPath) 
    objRegistry.EnumKey HKEY_USERS, strKeyPath, arrSubkeys 

    If IsArray(arrSubkeys) Then 
        For Each strSubkey In arrSubkeys 
            DeleteSubkeys HKEY_USERS, strKeyPath & "\" & strSubkey 
        Next 
    End If 

    objRegistry.DeleteKey HKEY_USERS, strKeyPath 
End Sub

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Vicki05Author Commented:
Does not work
0
 
becraigCommented:
What error do you get ?

I just tested this on my system and it works.

You intially had the wrong registry path:
strKeyPath = "\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Digest"
instead of
strKeyPath = ".DEFAULT\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Digest"

Can you give me an idea of what is not working ?

It is hard to figure out since it works for me on my system:
C:\Users\Administrator\Desktop>reg query "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings
    User Agent    REG_SZ    Mozilla/4.0 (compatible; MSIE 8.0; Win32)
    IE5_UA_Backup_Flag    REG_SZ    5.0
    ZonesSecurityUpgrade    REG_BINARY    F5511E7B469FCE01
    EnableNegotiate    REG_DWORD    0x1
    ProxyEnable    REG_DWORD    0x0

HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Lockdown_Zones
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones

C:\Users\Administrator\Desktop>cscript delreg.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.


C:\Users\Administrator\Desktop>reg query "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
ERROR: The system was unable to find the specified registry key or value.

Open in new window

0
 
Vicki05Author Commented:
It runs fine but does not delete the path or the sub keys
0
 
becraigCommented:
Can you simply open up  regedit and right click on the key an copy key name.
Then simply replace
strKeyPath = ".DEFAULT\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Digest"

with
strKeyPath = "<whatever the value is that you get>"

it would be unusual to work for me and not for you unless you are not running your command prompt as administrator.
0
 
Vicki05Author Commented:
I am using your edited script. I even tried creating keys. It still does not delete. This is Windows XP computer. I changed digest to Lock


On Error Resume Next

Const HKEY_USERS = &H80000003

strComputer = "."
strKeyPath = ".DEFAULT\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Lock"

Set objRegistry = GetObject("winmgmts:\\" & _
    strComputer & "\root\default:StdRegProv")

DeleteSubkeys HKEY_USERS, strKeypath

Sub DeleteSubkeys(HKEY_USERS, strKeyPath)
    objRegistry.EnumKey HKEY_USERS, strKeyPath, arrSubkeys

    If IsArray(arrSubkeys) Then
        For Each strSubkey In arrSubkeys
            DeleteSubkeys HKEY_USERS, strKeyPath & "\" & strSubkey
        Next
    End If

    objRegistry.DeleteKey HKEY_USERS, strKeyPath
End Sub

msgbox "Done"
0
 
becraigCommented:
Are you running as Administrator ?
0
 
becraigCommented:
why not make it simple then:

Just run the following command.


reg delete "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Lock"  /f
0
 
Vicki05Author Commented:
Lock was used as a test. I need to delete the digest folder and all the things underneath it.

strKeyPath = "\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Digest"
0
 
becraigCommented:
Ok so my last comment was to simply use the reg delete command, did you see or try that ?

reg delete "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Lock"  /f
0
 
Vicki05Author Commented:
Yes I did, but it did not work since there is subkeys and another folder under Digest folder. I am not trying to delete the lock folder. I tried again to delete the lock folder using what you gave. This is what I got. I used WshShell

Dim WshShell, bKey
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Lock"  /f

I--untitled.bmp
0
 
becraigCommented:
So I think we mixed two things here
reg delete "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Lock"  /f  

Open in new window

was just meant to be a windows command that would run from a command prompt, not to be inserted into the VBscript.

This is a command that should be able to run on its own and delete the entire key.
0
 
Vicki05Author Commented:
I am looking for a vbscript that will delete digest folder and all the subkeys.
0
 
Martin LissRetired ProgrammerCommented:
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
0
 
becraigCommented:
The comment: http:#a40398021

Provided a proven working example of how to accomplish this, the author was unable to provide any specific details as to why this did not work on their system.

In a nutshell the script does exactly what the author requested and was tested with posted results,
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now