find registry value with vbscript

Hi

i want to write a script that search for the value OptionsFile and and the value data would be C:\Program Files\Tivoli\TSM\tdpsql\dsm.opt and its under the key Parameters
the problem is that i don't known the right key because its may be different name for every server - i know that the key in under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

i attach print script to this question the key Tsm Sql Scheduler could be diffrent name for every server
the Parameters key is permanent

if the   OptionsFile value is write i need to replace  it


Thx
vb scriptAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kanti PrasadCommented:
Hi

The below script will help to find and replace reg values

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/Q_23178275.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vb scriptAuthor Commented:
hi

i cant see this script

can you copy paste to here please ?
0
Kanti PrasadCommented:
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

Open in new window

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

frankhelkCommented:
How about that:

Dim winShl
Dim regVal
Set winShl = CreateObject("WScript.Shell")
regVal = winShl.RegRead("someRegKey")

Open in new window

0
vb scriptAuthor Commented:
hi frankhelk

this what i need :
Dim winShl
Dim regVal
Set winShl = CreateObject("WScript.Shell")
regVal = winShl.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\adsi\Cache\PerMachine")
wscript.echo regVal

the cache is the registry i don't know exactly his name

i need something like this

Dim winShl
Dim regVal
Set winShl = CreateObject("WScript.Shell")
regVal = winShl.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\adsi\.\PerMachine")
wscript.echo regVal
0
frankhelkCommented:
OK - the solution I gave you reads a value with an exactly known registry path.

If you don't know the eact location, you'll have to iterate thru the respective registry key ... there are several ways to do that, and I don't want to post other people's code.

If you squeeze a serch engine for "WScript.Shell parse registry vbs" you should get a load of examples ...
0
vb scriptAuthor Commented:
hi
i found this code
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

Sub EnumerateKeys(hive, key)
  WScript.Echo key
  reg.EnumKey hive, key, arrSubKeys
  If Not IsNull(arrSubKeys) Then
    For Each subkey In arrSubKeys
      EnumerateKeys hive, key & "\" & subkey
    Next
  End If
End Sub

Set reg = GetObject("winmgmts://./root/default:StdRegProv")

EnumerateKeys HKEY_LOCAL_MACHINE, strKeyPath

but this search for key , i need to search inside the key like

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player ActiveX\Helplink

this script search in uninstall key for subkey and i need to search key & subkey & Helplink ( value )
0
frankhelkCommented:
That script uses recusion to enumerate all keys within a given key, but it does nothing with that.

Besides of calling EnumerateKeys () again to dive deeper into the subkeys, it should enumerate the values, too with reg.EnumValues and i.e. add their paths to a list of values (probably with pre-filtering them). After parsing everything in the subkey you could use the list to find the values key(s) you're really interested in.

P.S.: In the  aspect of that post, a "key" is like a directory on a disk, a "subkey" is like a subdirectory, and a "value" is like a file on the disk, which has some content ... a somewhat irritating naming convention from Microsoft ....
0
vb scriptAuthor Commented:
i want to write a script that search for the value OptionsFile and and the value data would be C:\Program Files\Tivoli\TSM\tdpsql\dsm.opt and its under the key Parameters
the problem is that i don't known the right key because its may be different name for every server - i know that the key in under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

i attach print script to this question the key Tsm Sql Scheduler could be diffrent name for every server
the Parameters key is permanent

if the   OptionsFile value is write i need to replace  it


Thx

can you help with this please ? this is excatly what i need ?
0
vb scriptAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for vb script's comment #a40880902

for the following reason:

good
0
vb scriptAuthor Commented:
good
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.