Jump to content

Using wildcards with RegRead


Recommended Posts

Trying to figure out a way to determine if Marimba installed certain patches on a machine. 

If I look in the registry @ "HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMarimbaPatchService", I will see things like...

HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMarimbaPatchServiceMS13-004.Q2742595.NDP40-KB2742595-x64.exe._1735570611

and

HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMarimbaPatchServiceMS12-082.Q2770660.Windows6.1-Windows7-SP1-KB2770660-x64.msu.418434346

if Marimba installed those patches. 

The list of patches will change monthly, and will be kept in a list on a .txt file (easiest for co-workers to keep up to date) and will look something like this... 

KB2794707
KB2870699
KB2760769
KB2760597
KB2687423
KB2876315
KB2872339

I already have the script reading line by line, and pulling each KB# out and assigning it to a variable

What I cannot figure out is how to search for the registry Key based on that KB#

I tried this (which obviously didn't work)

Func ExistsInRegistry2 ()
   RegRead($keyroot & "*" & $line & "*" ,"")
   If @Error = "0" Then  ;Key exists
      MsgBox(0, $line, "found in registry")
      $exists = "found"
   Else       ;Key does not exist
      MsgBox(0, $line, "Not found in registry")
      $exists = "NotFound"
   EndIf
   Return $exists
EndFunc

I'm guessing that I need to use some combo of StringInStr and RegRead... but it's just not clicking for me 

I'm a novice programmer, so please forgive my ignorance
 

Link to comment
Share on other sites

  • Moderators

Hi, jerseyzuks. You could use EnumRegKey, like this, to get your values:

For $i = 1 To 100
    $val = RegEnumKey("HKLM\SOFTWARE\Wow6432Node\Marimba\PatchService", $i)
        If @error Then
            ExitLoop
        Else
            MsgBox(0, "", $val)
        EndIf
Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Just in case anyone else needs to do something like this in the future.  Forgive me if it is sloppy, but it does exactly what I needed it to do

;First we need to determine if this is an XP machine or a Win 7 Machine, because the patches will be different
Global $OS = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName")
Global $PatchFile
Global $File
Global $exists
Global $line
Global $keyroot

Call ("createReport")
Call ("SetPatchfileName")
Call ("SetKeyRoot")
Call ("GetKB")
Call ("OpenReport")
call ("ExistsInRegistry3")

Func createReport ()
   FileDelete(@MyDocumentsDir &  "\Patches.txt")
   $file = FileOpen(@MyDocumentsDir & "\patches.txt", 1) ;   the "9" is a combo of 1 = Write mode (append to end of file)  8 = Create directory structure if it doesn't exist
      If $file = -1 Then
         MsgBox(0, "Error", "Unable to open the report file")
      Exit
  EndIf
EndFunc

Func SetPatchfileName ()
   If $OS = ("Microsoft Windows XP") Then
      $PatchFile = ("LastMonthsXPPatches.txt")
   ElseIf $OS = ("Windows 7 Enterprise") Then
      $PatchFile = ("LastMonthsWin7Patches.txt")
   EndIf
EndFunc

Func SetKeyRoot ()
   If $OS = ("Microsoft Windows XP") Then
      $keyroot = "HKEY_LOCAL_MACHINE\SOFTWARE\Marimba\PatchService"
   ElseIf $OS = ("Windows 7 Enterprise") Then
      $keyroot = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Marimba\PatchService"
   EndIf
EndFunc
   

Func GetKB ()
   Local $patchfileopen = FileOpen($Patchfile)
   If $patchfileopen = -1 Then  
      MsgBox (1, "error", "unable to open the .txt file containing the patches")
   EndIf   
   
   While 1
      $line = FileReadLine($Patchfileopen)
      If @error = -1 Then ExitLoop
      ;MsgBox(0, "Line read:", $line)
      Call ("ExistsInRegistry")
      if $exists = "found" then
         FileWriteLine($file, $line & " was found in registry")
      Else 
         FileWriteLine($file, "#####Error#### " & $line & " was not found")
     EndIf
   WEnd
EndFunc
   
Func ExistsInRegistry ()
   For $i = 1 To 1000
      $val = RegEnumKey($keyroot, $i)
         If @error Then
            MsgBox(0, "", $line & " Not Found")
            $exists = "Not Found"
            ExitLoop
         EndIf
         
         If StringInStr($val, $line, 2) Then
            $exists = "found"
            ExitLoop
         EndIf
   Next
 EndFunc
 
Func OpenReport ()
ShellExecute (@MyDocumentsDir &  "\Patches.txt") ; Displays the report after all the individual scrips are run
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...