Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-07-30
3
Medium Priority
?
1,084 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

824 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