Solved

VBScript to find a user profile within the registry and delete some keys

Posted on 2014-07-30
3
892 Views
Last Modified: 2014-08-01
I am trying to figure out how to create a VB script that does the following..

1. Find the USERNAME of the current logged in user.
2. Takes that value and searches within HKEY_USERS for the profile that contains that username under Volatile Environment under the USERNAME key.
3. When it successfully finds a match, it then searches within that registry profile and deletes the following:

HKEY_USERS\%USERPROFILE%\Software\Microsoft\Windows\CurrentVersion\Policies\Ext\
      Delete CLSID

HKEY_USERS\%USERPROFILE%\Software\Microsoft\Windows\CurrentVersion\Ext\Settings\
      Delete {0A9CDB52-EBDF-4210-9C6A-B90C2FD410AB}

HKEY_USERS\%USERPROFILE%\Software\Microsoft\Windows\CurrentVersion\Ext\Stats
      Delete {0A9CDB52-EBDF-4210-9C6A-B90C2FD410AB}

Could anyone take a crack at this? This is much too advanced for me to figure out...

Thank you.
0
Comment
Question by:prologic08
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 40233188
Hi, instead of finding the volatile environment username, I have determined the account SID that would exist under HKEY_USERS, and used that.

I have commented out the objShell.RegDelete line in this code so you can see what it would delete.

Regards,

Rob.

Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objAccount = objWMIService.Get("Win32_UserAccount.Name='" & objNetwork.UserName & "',Domain='" & objNetwork.UserDomain & "'")
strRegRoot = "HKEY_USERS\" & objAccount.SID & "\Software\Microsoft\Windows\CurrentVersion\"
arrValuesToDelete = Array("Policies\Ext\CLSID", "Ext\Settings\{0A9CDB52-EBDF-4210-9C6A-B90C2FD410AB}", "Ext\Stats\{0A9CDB52-EBDF-4210-9C6A-B90C2FD410AB}")
For Each strValue In arrValuesToDelete
	strFullValue = strRegRoot & strValue
	WScript.Echo "Deleting " & strFullValue
	On Error Resume Next
	'objShell.RegDelete strFullValue
	Err.Clear
	On Error GoTo 0
Next

Open in new window

0
 

Author Comment

by:prologic08
ID: 40234350
Rob, this is exactly what I need! The logic makes sense to me and will be useful in other projects that are similar to this one. Thank you very much for taking the time to do this.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40235495
No problem. Glad it worked out for you.

Thanks for the grade

Rob.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

747 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

13 Experts available now in Live!

Get 1:1 Help Now