Jump to content

Help to read @ (Default value) in Registry?


Recommended Posts

Can someone help me figure out why i cant capture it?

i can evaluate if its <> from "" , but not capture it???

here is my function

If @OSArch = "X64" Then
Global $key7 = "HKLM64"
Global $key8 = "HKCU64"

Else
Global $key7 = "HKLM"
Global $key8 = "HKCU"
EndIf
Func _ComputerGetSoftwareny()
Local Const $UnInstKey = $key7 & "SOFTWAREMicrosoftWindowsCurrentVersionUninstall"
Local $i = 1
Dim $aSoftwareInfo[1][7]
local $mac=_GetMAC()
While 1
  $AppKey = RegEnumKey($UnInstKey, $i)
  If @error <> 0 Then ExitLoop
  ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][7]
  $aSoftwareInfo[$i][0] = @ComputerName
  $aSoftwareInfo[$i][1] = $mac
  $aSoftwareInfo[$i][2] = StringStripWS(StringReplace(RegRead($UnInstKey & "" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
  if RegRead($UnInstKey & "" & $AppKey, "") = "" Then
   $aSoftwareInfo[$i][3] = RegRead($UnInstKey & "" & $AppKey, "")
;   $aSoftwareInfo[$i][3] = "KB patch"
  Else
   $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "" & $AppKey, "DisplayVersion"), 3)
  EndIf
  $aSoftwareInfo[$i][4] = StringStripWS(RegRead($UnInstKey & "" & $AppKey, "Publisher"), 3)
  ; $text = StringReplace("this is a line of text", " ", "-")
  ;  $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "" & $AppKey, "UninstallString"), 3)
  $aSoftwareInfo[$i][5] = StringReplace(RegRead($UnInstKey & "" & $AppKey, "UninstallString"), "", "")
  $aSoftwareInfo[$i][6] = StringReplace(RegRead($UnInstKey & "" & $AppKey, "InstallDate"), "", "")
  $i += 1
WEnd
$aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
If $aSoftwareInfo[0][0] < 1 Then
  SetError(1, 1, 0)
EndIf
Return $aSoftwareInfo
EndFunc   ;==>_ComputerGetSoftware

this is the result

---

$updatesoftware-> |SPEL|00-FF-B9-F3-31-93|Microsoft Visual C# 2008 Express Edition with SP1 - ENU||Microsoft Corporation|MsiExec.exe /X{A4418082-E601-3954-805B-D56A2B50EC8B}|20110804|

$updatesoftware-> |SPEL|00-FF-B9-F3-31-93||||||

$updatesoftware-> |SPEL|00-FF-B9-F3-31-93|Security Update for Microsoft Visual C# 2008 Express Edition with SP1 - ENU (KB2251487)|1|Microsoft Corporation|C:WINDOWSsystem32msiexec.exe /package {A4418082-E601-3954-805B-D56A2B50EC8B} /uninstall {BEBED0E2-B204-388A-A53B-30DA66FA8ACC} /qb+ REBOOTPROMPT=""||

$updatesoftware-> |SPEL|00-FF-B9-F3-31-93||||||

$updatesoftware-> |SPEL|00-FF-B9-F3-31-93|Hotfix for Microsoft Visual C# 2008 Express Edition with SP1 - ENU (KB945282)|1|Microsoft Corporation|C:WINDOWSsystem32msiexec.exe /package {A4418082-E601-3954-805B-D56A2B50EC8B} /uninstall /qb+ REBOOTPROMPT=""||

---

These lines

$updatesoftware-> |SPEL|00-FF-B9-F3-31-93||||||

should look like

$updatesoftware-> |SPEL|00-FF-B9-F3-31-93|KB patch something|||||

Edited by lgvlgv
Link to comment
Share on other sites

Me thinks your If/Then logic is messed up.

You're saying "If the default is blank then move the default value to the array".

$aSoftwareInfo[$i][3] = RegRead($UnInstKey & "" & $AppKey, "")
If $aSoftwareInfo[$i][3] = "" Then $aSoftwareInfo[$i][3] = RegRead($UnInstKey & "" & $AppKey, "DisplayVersion")
Link to comment
Share on other sites

yes, im trying to do like the helpfile says

registry key must start with "HKEY_LOCAL_MACHINE" ("HKLM") or "HKEY_USERS" ("HKU") or "HKEY_CURRENT_USER" ("HKCU") or "HKEY_CLASSES_ROOT" ("HKCR") or "HKEY_CURRENT_CONFIG" ("HKCC").

When running on 64-bit Windows if you want to read a value specific to the 64-bit environment you have to suffix the HK... with 64 i.e. HKLM64.

AutoIt supports registry keys of type REG_BINARY, REG_SZ, REG_MULTI_SZ, REG_EXPAND_SZ, and REG_DWORD.

To access the (Default) value use "" (a blank string) for the valuename.

When reading a REG_BINARY key the result is a binary datatype (in previous versions it was a string of hex characters).

When reading a REG_MULTI_SZ key the multiple entries are separated by @LF - use with StringSplit(..., @LF) to get each entry.

It is possible to access remote registries by using a keyname in the form "computernamekeyname". To use this feature you must have the correct access rights.

Link to comment
Share on other sites

Maybe RegSearch will help

We were discussing this a few days ago

The default entry is not easy to obtain, have a read

;*****************************************************
; Function _RegSearch($sStartKey, $sSearchVal, $iType = 0x07, $fArray = False)
;   Where:  $sStartKey = Reg path at which to begin search
;          $sSearchVal = The string to search for
;          $iType = Matching types to return:
;              1 = Key names
;              2 = Value names
;              4 = Value data
;              Add bits together for multiple match types, default is 7 (all)
;          $fArray = Return an array of results vice the string (default = False)
;   Performs a recursive search of the registry starting at $sStartKey, looking for $sSearchVal
;   Returns a string containing a list of key names and values.
;   If a key name matches, it is listed as a reg path with trailing backslash:
;    i.e. HKLMSOFTWAREMicrosoftWindowsCurrentVersion
;   If a value name matches, it is listed as a reg path without trailing backslash:
;    i.e. HKLMSOFTWAREMicrosoftWindowsCurrentVersionWallPaperDir
;   If the data matches, the format is path = data:
;     i.e. HKLMSOFTWAREMicrosoftWindowsCurrentVersionWallPaperDir = %SystemRoot%WebWallpaper
;   If $fArray is True, then return data is an array with [0] = count.
;*****************************************************
; Change Log:
;  v1.0.0.0  |  03/17/05  |  Original SearchReg() by Holger
;  v2.0.0.0  |  08/10/06  |  Native AutoIt version by PsaltyDS
;  v2.0.0.1  |  08/16/06  |  Fixed bug reported by markloman
;  v2.0.1.0  |  07/30/08  |  Added $iType and $fArray parameters
;*****************************************************
Func _RegSearch($sStartKey, $sSearchVal, $iType = 0x07, $fArray = False)
    Local $v, $sVal, $k, $sKey, $sFound = ""
; Generate type flags
    If Not BitAND($iType, 0x07) Then Return SetError(1, 0, 0); No returns selected
    Local $fKeys = BitAND($iType, 0x1), $fValue = BitAND($iType, 0x2), $fData = BitAND($iType, 0x4)
; This checks values and data in the current key
    If ($fValue Or $fData) Then
        $v = 1
        While 1
            $sVal = RegEnumVal($sStartKey, $v)
            If @error = 0 Then
            ; Valid value - test its name
                If $fValue And StringInStr($sVal, $sSearchVal) Then $sFound &= $sStartKey & "" & $sVal & @LF
            ; test its data
                If $fData Then
                    $readval = RegRead($sStartKey, $sVal)
                    If StringInStr($readval, $sSearchVal) Then
                        $sFound &= $sStartKey & "" & $sVal & " = " & $readval & @LF
                    EndIf
                EndIf
                $v += 1
            Else
            ; No more values here
                ExitLoop
            EndIf
        WEnd
    EndIf
; This loop checks subkeys
    $k = 1
    While 1
        $sKey = RegEnumKey($sStartKey, $k)
        If @error = 0 Then
        ; Valid key - test it's name
            If $fKeys And StringInStr($sKey, $sSearchVal) Then $sFound &= $sStartKey & "" & $sKey & "" & @LF
        ; Now search it
            $sFound &= _RegSearch($sStartKey & "" & $sKey, $sSearchVal, $iType) & @LF
        Else
        ; No more keys here
            ExitLoop
        EndIf
        $k += 1
    WEnd
; Return results
    If StringRight($sFound, 1) = @LF Then $sFound = StringTrimRight($sFound, 1)
    If $fArray Then
        Return StringSplit($sFound, @LF)
    Else
        Return $sFound
       
    EndIf
EndFunc  ;==>_RegSearch
Link to comment
Share on other sites

So you fixed the broken/backwards/incorrect If-Then-Else statement from your example post, that would only populate your array with the default value if the default value was empty, and it still doesn't work?

Correcting the bug, or using the 2 lines I posted, worked fine for me. Array element 3 contained the default value if it existed, if not, then the version number was loaded.

Edited by Spiff59
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...