?
Solved

Delete Value and keys from the Registry using VBscript

Posted on 2014-10-22
18
Medium Priority
?
548 Views
Last Modified: 2014-11-18
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
Comment
Question by:Vicki05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
18 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40397745
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
 

Author Comment

by:Vicki05
ID: 40397870
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
 
LVL 29

Expert Comment

by:becraig
ID: 40397969
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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 

Author Comment

by:Vicki05
ID: 40397998
Does not work
0
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 40398021
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
 

Author Comment

by:Vicki05
ID: 40398033
It runs fine but does not delete the path or the sub keys
0
 
LVL 29

Expert Comment

by:becraig
ID: 40398048
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
 

Author Comment

by:Vicki05
ID: 40398064
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
 
LVL 29

Expert Comment

by:becraig
ID: 40398078
Are you running as Administrator ?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40398118
why not make it simple then:

Just run the following command.


reg delete "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Lock"  /f
0
 

Author Comment

by:Vicki05
ID: 40399416
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
 
LVL 29

Expert Comment

by:becraig
ID: 40400430
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
 

Author Comment

by:Vicki05
ID: 40400492
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
 
LVL 29

Expert Comment

by:becraig
ID: 40400513
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
 

Author Comment

by:Vicki05
ID: 40406337
I am looking for a vbscript that will delete digest folder and all the subkeys.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40450908
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
 
LVL 29

Expert Comment

by:becraig
ID: 40450909
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question