search value in registry key - unknown key path

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
OptionsFile=C:\Program Files\Tivoli\TSM\tdpsql\dsm.opt

if its equel i need to change 2 other registry key

the big problem is that i don't really known the right key path  because its may be different name for every server - i know that the key in under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
the key is under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

Thx
vb scriptAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

vb scriptAuthor Commented:
i need to writr this on vbscript sorry
pcelbaCommented:
Hmm... You may call PowerShell from VBscript: http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/18/how-to-use-vbscript-to-run-a-powershell-script.aspx

You may also operate on registry via WMI from VBScript directly: http://www.robvanderwoude.com/vbstech_registry_wshshell.php

This MSDN link can provide more info about WMI: https://msdn.microsoft.com/en-us/library/aa394600.aspx
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

vb scriptAuthor Commented:
hi

i know this script

the problem that i have i that  the key that start with the word TSM is under this path : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services , and the value that i want to find is :
OptionsFile=C:\Program Files\Tivoli\TSM\tdpsql\dsm.opt

so all of this scripts need the full path to the registry key - that path i really don't know

i need vbs that will search this key under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

and if he will find that i need to search the value that is under the parameter registry key .

thx
pcelbaCommented:
That was the reason I've recommended the PowerShell. You may simply list all the keys and select the right one based on the filter or another criteria evaluated in a loop or in an in-line loop. You may even define Regexp to find the key etc. etc.

Anyway you have to be logged in as admin so why not to call PowerShell script from VBS?

OK, you may start with this code which should work after certain updates:
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_ 
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Services"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
WScript.Echo "Subkeys under " _
    & "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services"
For Each subkey In arrSubKeys
    If (IsNull( arrSubKeys ) = false) Then
    WScript.Echo subkey

Next

Open in new window

Source
vb scriptAuthor Commented:
hi

i try this but this not work for me

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TSM Client Acceptor\Parameters

and this is the value that i search -
OptionsFile"="C:\\Program Files\\Tivoli\\TSM\\baclient\\dsm.opt

this it what i need to find but the key "TSM Client Acceptor" on every server is with different name

how can i find this with vbs ?

Thx
HackooCommented:
You can start with this vbscript :

'RegSrch.vbs - Search Registry for input string and display results.
'© Bill James - wgjames@mvps.org
' revised 20 Apr 2001 (parses regfile ~3X faster)
' revised 13 Dec 2001 (added Regedit command line switch for Win2K/WindXP)
 
Option Explicit
Dim oWS : Set oWS = CreateObject("WScript.Shell")
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
 
Dim sSearchFor
sSearchFor = InputBox("This script will search your Registry and find all " & _
             "instances of the search string you input."  & vbcrlf & vbcrlf & _
             "This search could take several minutes, so please be patient." & _
             vbcrlf & vbcrlf & "Enter search string (case insensitive) and " & _
             "click OK...", WScript.ScriptName & " " & Chr(169) & " Bill James")
 
If sSearchFor = "" Then Cleanup()
 
Dim StartTime : StartTime = Timer
 
Dim sRegTmp, eRegLine, iCnt, sRegKey, aRegFileLines, sOutAdd, sOutRemove, OutAdd, OutRemove
 
sRegTmp = oWS.Environment("Process")("Temp") & "\RegTmp.tmp"
sOutAdd = oWS.Environment("Process")("Temp") & "\sOutAdd" & Hour(Now) & Minute(Now) & Second(Now) & ".reg"
sOutRemove = oWS.Environment("Process")("Temp") & "\sOutRemove" & Hour(Now) & Minute(Now) & Second(Now) & ".reg"
 
oWS.Run "regedit /e /a " & sRegTmp, , True '/a enables export as Ansi for WinXP
 
set OutAdd = oFSO.OpenTextFile(sOutAdd, 8, True)
set OutRemove = oFSO.OpenTextFile(sOutRemove, 8, True)
 
OutAdd.WriteLine("REGEDIT4" & vbcrlf & "; " & WScript.ScriptName & " " & _
    Chr(169) & " Bill James" & vbcrlf & vbcrlf & "; Registry search " & _
    "results for string " & Chr(34) & sSearchFor & Chr(34) & " " & Now & _
    vbcrlf & vbcrlf & "; NOTE: This file will be deleted when you close " & _
    "WordPad." & vbcrlf & "; You must manually save this file to a new " & _
    "location if you want to refer to it again later." & vbcrlf & "; (If " & _
    "you save the file with a .reg extension, you can use it to restore " & _
    "any Registry changes you make to these values.)" & vbcrlf)
 
OutRemove.WriteLine("REGEDIT4" & vbcrlf & "; " & WScript.ScriptName & " " & _
    Chr(169) & " Bill James" & vbcrlf & vbcrlf & "; Registry search " & _
    "results for string " & Chr(34) & sSearchFor & Chr(34) & " " & Now & _
    vbcrlf & vbcrlf & "; NOTE: This file will be deleted when you close " & _
    "WordPad." & vbcrlf & "; You must manually save this file to a new " & _
    "location if you want to refer to it again later." & vbcrlf & "; (If " & _
    "you save the file with a .reg extension, you can use it to restore " & _
    "any Registry changes you make to these values.)" & vbcrlf)
 
With oFSO.GetFile(sRegTmp)
  aRegFileLines = Split(.OpenAsTextStream(1, 0).Read(.Size), vbcrlf)
End With
 
oFSO.DeleteFile(sRegTmp)
 
For Each eRegLine in aRegFileLines
  If InStr(1, eRegLine, "[", 1) > 0 Then sRegKey = eRegLine
  If InStr(1, eRegLine, sSearchFor, 1) >  0 Then
    If sRegKey <> eRegLine Then
      OutAdd.WriteLine(vbcrlf & sRegKey) & vbcrlf & eRegLine
      OutRemove.WriteLine(vbcrlf & "[-" & mid(sRegKey,2)) & vbcrlf & eRegLine
    Else
      OutAdd.WriteLine(vbcrlf & sRegKey)
      OutRemove.WriteLine(vbcrlf & "[-" & mid(sRegKey,2))
    End If
    iCnt = iCnt + 1
  End If
Next
 
Erase aRegFileLines
 
If iCnt < 1 Then
  oWS.Popup "Search completed in " & FormatNumber(Timer - StartTime, 0) & " seconds." & _
            vbcrlf & vbcrlf & "No instances of " & chr(34) & sSearchFor & chr(34) & _
            " found.",, WScript.ScriptName & " " & Chr(169) & " Bill James", 4096
  .Close
  oFSO.DeleteFile(sOutTmp)
  Cleanup()
End If
 
OutAdd.Close
OutRemove.Close
 
oWS.Popup "Search completed in " & FormatNumber(Timer - StartTime, 0) & " seconds." & _
          vbcrlf & vbcrlf & iCnt & " instances of " & chr(34) & sSearchFor & chr(34) & _
          " found." & vbcrlf & vbcrlf & "Click OK to open Results in WordPad.",, _
          WScript.ScriptName & " " & Chr(169) & " Bill James", 4096
 
oWS.Run "WordPad " & sOutAdd, 3, True
oWS.Run "WordPad " & sOutRemove, 3, True
 
Cleanup()
 
Sub Cleanup()
  Set oWS = Nothing
  Set oFSO = Nothing
  WScript.Quit
End Sub

Open in new window

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 Hackoo

i cant work with this script do you have Another idea ?
vb scriptAuthor Commented:
i don'tt get any solution
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.