• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

VBScript to Rescurse through HKEYUSERS and to remove restricted sites from each SID

Need a VBScript to Rescurse through HKEY_USERS and to remove 1 or more  restricted sites from each SID.

I probably will have to load their hives, delete, then unload hive. But have not done before. Recently took up VBScripting a few months ago.

Thank You for any assistance.

Here is key I need to delete: HKEY_USERS\"WhateverSid"\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\FaceBook.com ,etc.
1 Solution
Here you go:
Const DOMAIN = "Facebook.com"
Const HKEY_USERS = &H80000003
Const ZMAP_REGKEY = "\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\"
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.EnumKey HKEY_USERS, "", arrSubkeys
For Each strSubkey in arrSubkeys
    strKeyPath = strSubkey & ZMAP_REGKEY & DOMAIN
    delRegKey HKEY_USERS, strKeyPath
Sub delRegKey(pHive, byVal pKey)
	Dim objReg, strSubkey, arrSubkeys, strKey, arrSplit, intReturn
	Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    ' Remove ending backslash (\) if exists
	If Right(pKey, 1) = "\" Then
		pKey = Left(pKey, Len(pkey) - 1)
	End If
	intReturn = objReg.EnumKey(pHive, pKey, arrSubkeys)
	If intReturn <> 0 Then Exit Sub 
    If isArray(arrSubkeys) Then	
        For Each strSubkey in arrSubkeys
            delRegKey pHive, pKey & "\" & strSubkey
    End If
    Wscript.Echo "Deleting key: " & pKey
    objReg.DeleteKey pHive, pKey
End Sub

Open in new window

InuyashaplAuthor Commented:
Modified it to open the ntuser.dat file, make change and unload hive. Thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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