Solved

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

Posted on 2014-07-30
3
967 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data Analysis 7 59
vb6 Where condition on dbo 2 31
Notepad++ Question 11 28
VBA - How to copy the data from workbook to workbook masterfile in VBA? 19 47
In this post we will learn different types of Android Layout and some basics of an Android App.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

751 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