Jump to content

Obtain a specfic Reg Key Value "string"


Go to solution Solved by water,

Recommended Posts

Good day,

From the following posting [Click_Me], Altin provided a rather interesting snippet for obtaining all of the values within a particular registry key?

Following is his solution:

For $i = 1 to 100
$var = RegEnumVal("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)

if @error <> 0 Then ContinueLoop
MsgBox(4096, $var, RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $var))
Next

And here is my example:

For $i = 7 To 7
    $var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments\Guitar Rig 5", $i)
    If @error = 7 Then ContinueLoop
    $me = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments\Guitar Rig 5", $var)
    MsgBox(4096, "SYSTEMID", $me)
    If $me = "00000000000000000000000000000000" Then
        MsgBox(4096, "Result", "Great!")
    Else
        MsgBox(4096, "Result", "Not Great!")
    EndIf
Next

What it is that I requiring is to be able to verify if a specific Reg Key "string" exists...and the above snippet does just that. However, my example is rather "messy" and I would appreciate it if someone with more expertise would "clean up that snippet".

As can be observed below, this particular Reg Key has seven values, and I need to verify the SYSTEMID string. I need to verify that the SYSTEMID string does not equal "00000000000000000000000000000000".

HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5
"ContentDir"="C:\\Program Files\\Common Files\\Native Instruments\\Guitar Rig 5"
"ContentVersion"="2.0"
"InstallDir"="C:\\Program Files\\Native Instruments\\Guitar Rig 5"
"InstallVSTDir"="C:\\Program Files\\Native Instruments\\VSTPlugins 32 bit"
"InstallVST64Dir"="C:\\Program Files\\Native Instruments\\VSTPlugins 64 bit"
"SNO"="XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"
"SYSTEMID"="00000000000000000000000000000000"
"KEY"="0000000000000000000000000000000000000000000000000000000000000000"

Any assistance in this matter would be greatly appreciated!

Link to comment
Share on other sites

Hello,

How is this?

$var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments\Guitar Rig 5", 7)
$me = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments\Guitar Rig 5", $var)
If $me = "00000000000000000000000000000000" Then
    MsgBox(4096, "Result", "Great!")
Else
    MsgBox(4096, "Result", "Not Great!")
EndIf

PS: I would prefer the employment of Switch|Case!

Edited by mr-es335
Update!
Link to comment
Share on other sites

Hello,

My completed script...thus far...

; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_VerifyRegistration()
; -----------------------------------------------
Func _VerifyRegistration()
    ; Source data
    Local $_Appname1 = "Gutar Rig 5"
    Local $_Appname2 = "Rammfire"
    Local $_Appname3 = "Reflektor"
    Local $_Appname4 = "Traktors 12"
    ; -----------------
    Local $_RegKeyname1 = "HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments\Guitar Rig 5"
    Local $_RegKeyname2 = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Rammfire"
    Local $_RegKeyname3 = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Reflektor"
    Local $_RegKeyname4 = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Traktors 12"
    ; -----------------
    Local $_RegIndexValue1 = 7
    Local $_RegIndexValue2 = 4
    Local $_RegIndexValue3 = 4
    Local $_RegIndexValue4 = 4
    ; -----------------
    Local $_RegValue1 = RegEnumVal($_RegKeyname1, $_RegIndexValue1)
    Local $_RegValue2 = RegEnumVal($_RegKeyname2, $_RegIndexValue2)
    Local $_RegValue3 = RegEnumVal($_RegKeyname3, $_RegIndexValue3)
    Local $_RegValue4 = RegEnumVal($_RegKeyname4, $_RegIndexValue4)
    ; -----------------
    Local $_RegValueString1 = RegRead($_RegKeyname1, $_RegValue1)
    Local $_RegValueString2 = RegRead($_RegKeyname2, $_RegValue2)
    Local $_RegValueString3 = RegRead($_RegKeyname3, $_RegValue3)
    Local $_RegValueString4 = RegRead($_RegKeyname4, $_RegValue4)
    ; -----------------------------------------------
    Local $sMessage = "Start" & @CRLF & @CRLF
    ; -----------------------------------------------
    If $_RegValueString1 = "00000000000000000000000000000000" Then
        ; If the $String [IS 0's], then Not Good!
        $sMessage &= "The App... [" & $_Appname1 & "] ...did not register correctly!" & @CRLF
    Else
        ; If the $String [IS NOT 0's], then Good!
        $sMessage &= "The App... [" & $_Appname1 & "] ...did register correctly!" & @CRLF
    EndIf
    ; -----------------------------------------------
    If $_RegValueString2 = "00000000000000000000000000000000" Then
        ; If the $String [IS 0's], then Not Good!
        $sMessage &= "The App... [" & $_Appname2 & "] ...did not register correctly!" & @CRLF
    Else
        ; If the $String [IS NOT 0's], then Good!
        $sMessage &= "The App... [" & $_Appname2 & "] ...did register correctly!" & @CRLF
    EndIf
    ; -----------------------------------------------
    If $_RegValueString3 = "00000000000000000000000000000000" Then
        ; If the $String [IS 0's], then Not Good!
        $sMessage &= "The App... [" & $_Appname3 & "] ...did not register correctly!" & @CRLF
    Else
        ; If the $String [IS NOT 0's], then Good!
        $sMessage &= "The App... [" & $_Appname3 & "] ...did register correctly!" & @CRLF
    EndIf
    ; -----------------------------------------------
    If $_RegValueString4 = "00000000000000000000000000000000" Then
        ; If the $String [IS 0's], then Not Good!
        $sMessage &= "The App... [" & $_Appname4 & "] ...did not register correctly!" & @CRLF
    Else
        ; If the $String [IS NOT 0's], then Good!
        $sMessage &= "The App... [" & $_Appname4 & "] ...did register correctly!" & @CRLF
    EndIf
    ; -----------------------------------------------
    $sMessage &= @CRLF & "End" & @CRLF
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $sMessage, 450, 215, -1, -1, 4, "FuturaBQ-DemiBold", 14)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>_VerifyRegistration
; -----------------------------------------------

I would love to incorporate "loops" , but an not sure how to do so with the varying "$_RegIndexValue's"?

Link to comment
Share on other sites

  • Solution

Have a look at Arrays in the AutoIt help file.
Move your data to a 2-dimensional array and you can loop throug the rows and columns like in Excel.
The following code is syntactically correct, but untested.

#include <Array.au3>

; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_VerifyRegistration()
; -----------------------------------------------
Func _VerifyRegistration()
    ; Source data
    Local $iNumberOfApps = 4, $iFieldsPerApp = 5
    ; Array holding the following data in columns for eaqch record: 0=Appname, 1=RegKeyname, 2=RegIndexValue, 3=RegValue, 4=RegValueString
    Local $aApps[$iNumberOfApps][$iFieldsPerApp] = [ _
            ["Gutar Rig 5", "HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments\Guitar Rig 5", 7], _
            ["Rammfire", "HKEY_LOCAL_MACHINE\Software\Native Instruments\Rammfire", 4], _
            ["Reflektor", "HKEY_LOCAL_MACHINE\Software\Native Instruments\Reflektor", 4], _
            ["Traktors 12","HKEY_LOCAL_MACHINE\Software\Native Instruments\Traktors 12", 4] _
            ]
    Local $sMessage = "Start" & @CRLF & @CRLF
    For $i = 0 To $iNumberOfApps - 1
        $aApps[$i][3] = RegEnumVal($aApps[$i][1], $aApps[$i][2])
        $aApps[$i][4] = RegRead($aApps[$i][1], $aApps[$i][3])
        If $aApps[$i][4] = "00000000000000000000000000000000" Then
            ; If the $String [IS 0's], then Not Good!
            $sMessage &= "The App... [" & $aApps[$i][0] & "] ...did not register correctly!" & @CRLF
        Else
        ; If the $String [IS NOT 0's], then Good!
            $sMessage &= "The App... [" & $aApps[$i][0] & "] ...did register correctly!" & @CRLF
        EndIf
    ; -----------------------------------------------
    Next
    _ArrayDisplay($aApps)
    ; -----------------------------------------------

    ; -----------------------------------------------
    $sMessage &= @CRLF & "End" & @CRLF
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $sMessage, 450, 215, -1, -1, 4, "FuturaBQ-DemiBold", 14)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>_VerifyRegistration
; -----------------------------------------------

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

water,

Thank you so very much of the snippet...appreciated...indeed!

It will take me some time to digest all that is going here. I am still attempting to "get me head around" single arrays [If that is the correct term to employ?]

For you...water..."Eau...Thank you!"

image.png

Edited by mr-es335
Link to comment
Share on other sites

Another good source to better understand arrays is the AutoIt wiki.

Two-dimensional arrays (as used in my exmple script above) are similar to MS Excel worksheets.

  • Data is stored in cells
  • You need two indices to access individual cells. The first for the row, the second for the column
  • The name of the array variable is similar to the name of the MS Excel Worksheet

Biggest difference between AutoIt and Excel:

  • The indices in AutoIt start with 0 whereas they start with 1 in MS Excel
  • Sometimes processing starts in row 1. But this is caused by the function that creates the array by using row 0 for the row and column count.

This should give you an easy start with arrays ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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