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

Posted on 2008-10-09
Last Modified: 2012-05-07
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\ ,etc.
Question by:Inuyashapl

Accepted Solution

si_shamil earned 225 total points
ID: 22683771
Here you go:
Const DOMAIN = ""

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


Author Closing Comment

ID: 31618363
Modified it to open the ntuser.dat file, make change and unload hive. Thank you.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now