/build/static/layout/Breadcrumb_cap_w.png

Yet another scripting need!

Hopefully one day I'll be able to help myself with these answers!

Ok, here's my problem:
I would like to search my registry, the whole registry, for a string, and delete all occurence of Keys AND/OR Values found matching this string.

Is this possible? Have checked a few sites out, and majority of them seem to concentrate on searching for Keys, but don't really mention values.

Have any of you guys used a similar VBScript that could help me out?

Thanks a lot!

Stephane

0 Comments   [ + ] Show comments

Answers (5)

Posted by: anonymous_9363 15 years ago
Red Belt
1
Holy Cow, Google for God's sake! Search term:

vbscript +registry +search +replace

The first hit got me the link below. I don't much like the use of Subs (a function would be able to return a False value for a failed get/set but...

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/Q_23178275.html
Posted by: Fau 15 years ago
Senior Purple Belt
1
Hello Ian,

Yes I had found this post, but I'm sadly not a member of ExpertsExchange.

Any other thoughts?

Stephane
Posted by: anonymous_9363 15 years ago
Red Belt
1
Sign up for the free 7-day trial: mine's been running for about 4.5 years now...

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
Set objShell = CreateObject("Wscript.Shell")
objShell.Run(strCommand), 1, True
Wscript.Quit
End If

' Duplicate these to account for each abbreviation
Const HKCR = &H80000000
Const HKEY_CLASSES_ROOT = &H80000000
Const HKCU = &H80000001
Const HKEY_CURRENT_USER = &H80000001
Const HKLM = &H80000002
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKUSERS = &H80000003
Const HKEY_USERS = &H80000003
Const HKCC = &H80000005
Const HKEY_CURRENT_CONFIG = &H80000005

'Value types
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7

strComputer = "."

Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "HKCU\Software"
If Right(strKeyPath, 1) = "\" Then strKeyPath = Left(strKeyPath, Len(strKeyPath) - 1)
strRoot = UCase(Left(strKeyPath, InStr(strKeyPath, "\") - 1))
strKeyPath = Mid(strKeyPath, InStr(strKeyPath, "\") + 1)

arrChanges = Array(_
"TestValueHere--|--TestValueChanged",_
"TestValue2--|--TestValue2Changed"_
)

For Each strChange In arrChanges
strValueToFind = Split(strChange, "--|--")(0)

strReplaceWith = Split(strChange, "--|--")(1)

Select Case strRoot
Case "HKCR", "HKEY_CLASSES_ROOT"
strRootKey = HKCR
Case "HKCU", "HKEY_CURRENT_USER"
strRootKey = HKCU
Case "HKLM", "HKEY_LOCAL_MACHINE"
strRootKey = HKLM
Case "HKUSERS", "HKEY_USERS"
strRootKey = HKUSERS
Case "HKCC", "HKEY_CURRENT_CONFIG"
strRootKey = HKCC
Case Else
MsgBox "Invalid root key entered."
WScript.Quit
End Select

strFoundAt = ""

SearchKeys strRootKey, strKeyPath, strValueToFind, strReplaceWith

WScript.Echo "Finished searching subkeys."

Next

Sub ChangeValue(strRootPath, strPath, strType, strReplacement)
Wscript.Echo strValueToFind & " was found at" & VbCrLf & _
strPath & VbCrLf & _
"Value Type: " & strType & VbCrLf
strKey = Left(strPath, InStrRev(strPath, "\") - 1)
strValue = Mid(strPath, InStrRev(strPath, "\") + 1)
Select Case strType
Case "String"
On Error Resume Next
intReturn = objRegistry.SetStringValue(strRootPath, strKey, strValue, strReplacement)
Err.Clear
On Error GoTo 0
Case "ExpandedString"
On Error Resume Next
intReturn = objRegistry.SetExpandedStringValue(strRootPath, strKey, strValue, strReplacement)
Err.Clear
On Error GoTo 0
Case "Binary"
On Error Resume Next
intReturn = objRegistry.SetBinaryValue(strRootPath, strKey, strValue, strReplacement)
Err.Clear
On Error GoTo 0
Case "DWord"
On Error Resume Next
intReturn = objRegistry.SetDWORDValue(strRootPath, strKey, strValue, strReplacement)
Err.Clear
On Error GoTo 0
Case "MultiString"
On Error Resume Next
intReturn = objRegistry.SetMultiStringValue(strRootPath, strKey, strValue, Array(strReplacement))
Err.Clear
On Error GoTo 0
End Select
If intReturn = 0 Then
WScript.Echo "Changed from " & strValueToFind & " to " & strReplaceWith & VbCrLf
Else
WScript.Echo "Failed to change from " & strValueToFind & " to " & strReplaceWith
End If
End Sub

Sub SearchKeys(strRootPath, strPath, strFind, strReplaceWith)
'strFoundAt = ""
SearchValues strRootPath, strPath, strFind, strReplaceWith
objRegistry.EnumKey strRootPath, strPath, arrSubkeys
If TypeName(arrSubkeys) <> "Null" Then
For Each objSubkey In arrSubkeys
'WScript.Echo strPath & "\" & objSubKey
SearchKeys strRootPath, strPath & "\" & objSubKey, strFind, strReplaceWith
Next
End If
End Sub

Sub SearchValues(strRootPath, strPath, strFind, strReplaceWith)
strType = ""
objRegistry.EnumValues strRootPath, strPath, arrValueNames, arrValueTypes
If TypeName(arrValueNames) <> "Null" Then
For intVal = LBound(arrValueNames) To UBound(arrValueNames)
Select Case arrValueTypes(intVal)
Case REG_SZ
If VarType(strFind) = vbString Then
objRegistry.GetStringValue strRootPath, strPath, arrValueNames(intVal), strValue
If strValue = strFind Then
strFoundAt = strPath & "\" & arrValueNames(intVal)
strType = "String"
End If
End If
Case REG_EXPAND_SZ
If VarType(strFind) = vbString Then
objRegistry.GetExpandedStringValue strRootPath, strPath, arrValueNames(intVal), strValue
If strValue = strFind Then
strFoundAt = strPath & "\" & arrValueNames(intVal)
strType = "ExpandedString"
End If
End If
Case REG_BINARY
If VarType(strFind) = vbByte Then
objRegistry.GetBinaryValue strRootPath, strPath, arrValueNames(intVal), strValue
If strValue = strFind Then
strFoundAt = strPath & "\" & arrValueNames(intVal)
strType = "Binary"
End If
End If
Case REG_DWORD
If VarType(strFind) = vbString Then
objRegistry.GetDWordValue strRootPath, strPath, arrValueNames(intVal), strValue
If strValue = strFind Then
strFoundAt = strPath & "\" & arrValueNames(intVal)
strType = "DWord"
End If
End If
Case REG_MULTI_SZ
If VarType(strFind) = vbString Then
objRegistry.GetMultiStringValue strRootPath, strPath, arrValueNames(intVal), arrValues
For Each strValue In arrValues
If strValue = strFind Then
strFoundAt = strPath & "\" & arrValueNames(intVal)
strType = "MultiString"
End If
Next
End If
End Select
If strFoundAt <> "" Then
ChangeValue strRootPath, strFoundAt, strType, strReplaceWith
strFoundAt = ""
End If
Next
End If
End Sub
Posted by: aogilmor 15 years ago
9th Degree Black Belt
1
ORIGINAL: VBScab
Sign up for the free 7-day trial: mine's been running for about 4.5 years now...

not any more, they ask for a credit card for the 14 day trial
too bad, it seems like a pretty good resource but I don't need another bill for something I can get for free with a little work. Glad it worked for you though! Just don't spread the word or they may start "cleaining up"!!!!
Posted by: Sguilly 14 years ago
Senior Yellow Belt
1
Hi,

For a long time now (at least a year 1/2) ExpertExchange have been providing free access to peoples answers/replies via a Google search, you just need to scroll all the way down the page, past all the sign up for free access gumff and search catagories, "Accepted Solution" will be at bottom of page in a green box :)

For the above question try searching via Google, VBScab's original search query "vbscript +registry +search +replace " it should be the first hit.

Steve G.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ