Solved

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

Posted on 2014-07-30
3
916 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

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

895 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

19 Experts available now in Live!

Get 1:1 Help Now