Search for registry key

hi to every body
i want to write a vb script that will search for key - the key is under - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\

the name of the key will start with "TSM"

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.

Bill PrewCommented:
Is it always right in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\, or could it be nested in subkeys below that?

~bp
0
Bill PrewCommented:
Give this a try.

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strMatch = "TSM"
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SYSTEM\CurrentControlSet\Services"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
intCount = 0 
For Each subkey In arrSubKeys
   If UCase(Left(subkey, Len(strMatch))) = UCase(strMatch) Then
      Wscript.Echo subkey
      intCount = intCount + 1
   End If
Next

If intCount = 0 Then
   Wscript.Echo "No keys found starting with """ & strMatch & """."
End If

Open in new window

~bp
0
vb scriptAuthor Commented:
Hi

your script work like charm , but i forgot something , What I want to write actually is such a thing
If the resulting value is equal to TSM so I want to check the following key - strKeyPath & "\" & subkey & "\ Parameters"
And below this key has a value named (REG_SZ) named OptionsFile and its value is equal to C: \ Program Files \ tivoli \ tsm \ baclient \ dsm.opt If all the conditions are right I want to change two values that are under strKeyPath & "\" & subkey & "\ Parameters "

Thanks in advance
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Bill PrewCommented:
Can you export that part of the registry from an example system and post the REG file here so i can test?  And include details on what values need to be changed.

~bp
0
vb scriptAuthor Commented:
Hi

here is the registry key
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TSM Client Scheduler\Parameters]
"OptionsFile"="C:\\Program Files\\Tivoli\\TSM\\baclient\\dsm.opt"
"ScheduleLog"="C:\\Program Files\\Tivoli\\TSM\\baclient\\dsmsched.log"
"ErrorLog"="C:\\Program Files\\Tivoli\\TSM\\baclient\\dsmerror.log"

The first condition is "OptionsFile"="C:\\Program Files\\Tivoli\\TSM\\baclient\\dsm.opt"

and if true i will change both value ScheduleLog And ErrorLog

Thx
0
frankhelkCommented:
Just meditating ... in my opinion there's no need to search for that special key by traversing thru the [HKLM\SYSTEM\CurrentControlSet\services] branch of the registry tree.

Just try to read the [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TSM Client Scheduler\Parameters\OptionsFile] value. Use a proper On Error statement to react on failure.

If the attept to read the value fails, it' supposedly simply not there - that results in an error and you could react on that where the On Error statement points to. Otherwise you get the value and could check that for the specific value.

That way you don't have to scrub the entire branch just to detect if the subkey is there.
0
vb scriptAuthor Commented:
hi

the name - TSM Client Scheduler is different on each server this why i search the word TSM
can you give an exmple please how to write this script
0
frankhelkCommented:
Hmmm - could you please give some examples how that part changes ? Making such registry key names kind of random seems strange to me ....
0
vb scriptAuthor Commented:
o.k
I will explain - the reason I'm looking for the key that starts with TSM reason may be more than one key that starts with TSM, movie importers renamed I want to check out the next OptionsFile which is equivalent to C: \ Program Files \ Tivoli \ TSM \ baclient \ dsm.opt and if all conditions There I met the two following values ScheduleLog and ErrorLog these values:
C: \ Program Files \ Tivoli \ TSM \ baclient \ ComputerName_sched.log
C: \ Program Files \ Tivoli \ TSM \ baclient \ ComputerName_error.log

If its possible here its a vbs that search for the Key that start with TSM - the problem is that i dont know how to complete the rest of the think.

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strMatch = "TSM"
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SYSTEM\CurrentControlSet\Services"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
intCount = 0
For Each subkey In arrSubKeys
   If UCase(Left(subkey, Len(strMatch))) = UCase(strMatch) Then
      Wscript.Echo subkey
      intCount = intCount + 1
   End If
Next

If intCount = 0 Then
   Wscript.Echo "No keys found starting with """ & strMatch & """."
End If


Thanks in advance
0
Bill PrewCommented:
Okay, this should do what you are describing, you just have to add whatever logic is needed to change the existing values to the new desired values.

Keep in mind this will need to be run with elevated privs in order to update the registry.

' Constant values
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strMatch = "TSM"

' Create register opject
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
 
' Access the root key we want to search 
strKeyPath = "SYSTEM\CurrentControlSet\Services"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
' Look for the desired key 
For Each strSubKey In arrSubKeys

   If UCase(Left(strSubKey, Len(strMatch))) = UCase(strMatch) Then
      ' When found process this key
      ProcessKey strKeyPath & "\" & strSubKey & "\Parameters"
   End If

Next

Sub ProcessKey(strKey)

   ' Look for "OptionsFile" value
   objReg.GetStringValue HKEY_LOCAL_MACHINE, strKey, "OptionsFile", strValue

   ' If found then update desired values
   If Not IsNull(strValue) Then

      ' Get current value of string
      objReg.GetStringValue HKEY_LOCAL_MACHINE, strKey, "ScheduleLog", strValue
      If Not IsNull(strValue) Then
         ' Adjust strValue as needed here, and then update
         strValue = Replace(strValue, "C:", "X:")
         objReg.SetStringValue HKEY_LOCAL_MACHINE, strKey, "ScheduleLog", strValue
      End If

      ' Get current value of string
      objReg.GetStringValue HKEY_LOCAL_MACHINE, strKey, "ErrorLog", strValue
      If Not IsNull(strValue) Then
         ' Adjust strValue as needed here, and then update
         strValue = Replace(strValue, "C:", "X:")
         objReg.SetStringValue HKEY_LOCAL_MACHINE, strKey, "ErrorLog", strValue
      End If

   End If

End Sub

Open in new window

~bp
0
vb scriptAuthor Commented:
hi

To change the value I need the value of OptionsFile will be equal to C: \ Program Files \ tivoli \ tsm \ baclient \ dsm.opt because in some cases it might be worth a different value
Where I make it in the script
0
Bill PrewCommented:
These lines (in two places):

         ' Adjust strValue as needed here, and then update
         strValue = Replace(strValue, "C:", "X:")


I gave you an example that changed the drive letter, but you can replace the whole string value with the desired one if that's your need.

~bp
0
frankhelkCommented:
OK - if a part of the registry path is uncertain, you'll definitely have to parse thru them.
0
vb scriptAuthor Commented:
I checked the script but I want him to do - if the value of OptionsFile will be equal to C: \Program Files \tivoli\tsm\baclient\dsm.opt only then is there a need to change the following values ScheduleLog  & ErrorLog to C:\ProgramFiles\tivoli\tsm\baclient\ComputerName_sch.log
C:\Program Files\tivoli\tsm\baclient\ComputerName_error.log

What that does is currently Script changing them regardless of the value OptionsFile

Is there a solution
0
vb scriptAuthor Commented:
hi again

i want to write this value C:\ProgramFiles\tivoli\tsm\baclient\ComputerName_sch.log to ScheduleLog
and C:\Program Files\tivoli\tsm\baclient\ComputerName_error.log to ErrorLog
not replace
0
Bill PrewCommented:
Okay, this should do what you described.

' Constant values
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strMatch = "TSM"

' Create register opject
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
 
' Access the root key we want to search 
strKeyPath = "SYSTEM\CurrentControlSet\Services"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
' Look for the desired key 
For Each strSubKey In arrSubKeys

   If UCase(Left(strSubKey, Len(strMatch))) = UCase(strMatch) Then
      ' When found process this key
      ProcessKey strKeyPath & "\" & strSubKey & "\Parameters"
   End If

Next

Sub ProcessKey(strKey)

   ' Look for "OptionsFile" value
   objReg.GetStringValue HKEY_LOCAL_MACHINE, strKey, "OptionsFile", strValue

   ' If found then update desired values
   If LCase(strValue) = LCase("C:\\Program Files\\tivoli\\tsm\\baclient\\dsm.opt") Then

      ' Get current value of string
      objReg.GetStringValue HKEY_LOCAL_MACHINE, strKey, "ScheduleLog", strValue
      If Not IsNull(strValue) Then
         strValue = "C:\\Program Files\\tivoli\\tsm\\baclient\\ComputerName_sch.log"
         objReg.SetStringValue HKEY_LOCAL_MACHINE, strKey, "ScheduleLog", strValue
      End If

      ' Get current value of string
      objReg.GetStringValue HKEY_LOCAL_MACHINE, strKey, "ErrorLog", strValue
      If Not IsNull(strValue) Then
         strValue = "C:\\Program Files\\tivoli\\tsm\\baclient\\ComputerName_error.log"
         objReg.SetStringValue HKEY_LOCAL_MACHINE, strKey, "ErrorLog", strValue
      End If

   End If

End Sub

Open in new window

~bp
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:
wondefull job
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.