vb script
asked on
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\ds m.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\ CurrentCon trolSet\Se rvices
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
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\ds
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\
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
How about that:
Dim winShl
Dim regVal
Set winShl = CreateObject("WScript.Shell")
regVal = winShl.RegRead("someRegKey")
ASKER
hi frankhelk
this what i need :
Dim winShl
Dim regVal
Set winShl = CreateObject("WScript.Shel l")
regVal = winShl.RegRead("HKEY_LOCAL _MACHINE\S YSTEM\Curr entControl Set\servic es\adsi\Ca che\PerMac hine")
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.Shel l")
regVal = winShl.RegRead("HKEY_LOCAL _MACHINE\S YSTEM\Curr entControl Set\servic es\adsi\.\ PerMachine ")
wscript.echo regVal
this what i need :
Dim winShl
Dim regVal
Set winShl = CreateObject("WScript.Shel
regVal = winShl.RegRead("HKEY_LOCAL
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.Shel
regVal = winShl.RegRead("HKEY_LOCAL
wscript.echo regVal
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 ...
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 ...
ASKER
hi
i found this code
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Window s\CurrentV ersion\Uni nstall"
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://./ro ot/default :StdRegPro v")
EnumerateKeys HKEY_LOCAL_MACHINE, strKeyPath
but this search for key , i need to search inside the key like
HKEY_LOCAL_MACHINE\SOFTWAR E\Microsof t\Windows\ CurrentVer sion\Unins tall\Adobe Flash Player ActiveX\Helplink
this script search in uninstall key for subkey and i need to search key & subkey & Helplink ( value )
i found this code
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Window
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://./ro
EnumerateKeys HKEY_LOCAL_MACHINE, strKeyPath
but this search for key , i need to search inside the key like
HKEY_LOCAL_MACHINE\SOFTWAR
this script search in uninstall key for subkey and i need to search key & subkey & Helplink ( value )
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 ....
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 ....
ASKER
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\ds m.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\ CurrentCon trolSet\Se rvices
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 ?
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\
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 ?
ASKER
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
Accepted answer: 0 points for vb script's comment #a40880902
for the following reason:
good
ASKER
good
ASKER
i cant see this script
can you copy paste to here please ?