Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
A short article about problems I had with the new location API and permissions in Marshmallow
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

740 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