Jump to content

Not reading registry key


 Share

Recommended Posts

Ok, I know i cannot be that hard to read registry keys. What I have done is written a simple GUI to read registry keys and display them into a window. I have imported my .reg file with my criteria and I am continually receiving @Error = 1 if unable to open requested key. Not sure why it will not read imported regkeys. I can read something like: RegRead( "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt", "Version" ) and it returns back v3.3.8.1.

If I use regwrite and write out what was in my .reg file it works fine. Problem is this .reg file I am using is created in WindowsPE to be used for reading back data once in Windows. VBScript works fine to read but not AutoIt.

Sample .reg file

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\SMUDO]

"ClientVersion"="7.4"

"ServerVersion"="7.3"

"AssetTag"="168197"

"InstallOption"="FULL"

"TimeZone"="Central Standard Time"

"Division"="BIS"

"Language"="English_United_States en-us 0409 0409:00000409"

"Version"="NAP 2.2"

"ImageFileDate"="12/21/2011"

Sample .au3 file

#include <GuiConstantsEx.au3>

#include <Constants.au3>

#include <WindowsConstants.au3>

_Main()

Func _Main()

Local $AssetTag = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\SMUDO", "AssetTag")

Local $client_ver = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\SMUDO", "ClientVersion")

Local $server_ver = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\SMUDO", "ServerVersion)

Local $Division = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\SMUDO", "Division")

Local $Language = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\SMUDO", "Language")

Local $langsplit = StringSplit($Language, " ", 0)

Local $Version = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\SMUDO", "Version")

GUICreate("Support Information", 300, 350, (@DesktopWidth - 300) / 2, (@DesktopHeight - 350) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

GUICtrlCreateLabel("Asset Tag:", 10, 10, 150, 20)

GUICtrlCreateLabel("Client Version:", 10, 30, 150, 20)

GUICtrlCreateLabel("Server Version:", 10, 50, 150, 20)

GUICtrlCreateLabel("Division:", 10, 70, 150, 20)

GUICtrlCreateLabel("Hardware:", 10, 90, 150, 20)

GUICtrlCreateLabel("Language:", 10, 110, 150, 20)

GUICtrlCreateLabel("Version:", 10, 130, 150, 20)

$Label_AssetTag = GUICtrlCreateLabel($AssetTag, 120, 10, 120, 20)

$Label_Clientver = GUICtrlCreateLabel($clientver, 120, 30, 120, 20)

$Label_Serverver = GUICtrlCreateLabel($serverver, 120, 50, 120, 20)

$Label_Division = GUICtrlCreateLabel($Division, 120, 70, 120, 20)

$Label_Hardware = GUICtrlCreateLabel($Hardware, 120, 90, 180, 20)

$Label_Language = GUICtrlCreateLabel($langsplit[1], 120, 110, 180, 20)

$Label_Version = GUICtrlCreateLabel($Version, 120, 130, 180, 20)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

Exit

EndFunc

Link to comment
Share on other sites

Hi,

Quote from help file

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.

if using 64bit os eg:
#include <GuiConstantsEx.au3>

_Main()

Func _Main()
    Local $sHKLM, $aValue, $sReturn
    $sHKLM = "HKLMSOFTWARESMUDO"
    If Not StringInStr(@OSArch, "X86") Then $sHKLM = StringReplace($sHKLM, "HKLM", "HKLM64")
    $aValue = StringSplit("AssetTag|ClientVersion|ServerVersion|Division|Hardware|Language", "|", 2)

    GUICreate("Support Information", 300, 350, (@DesktopWidth - 300) / 2, (@DesktopHeight - 350) / 2)
    For $i = 0 To UBound($aValue) - 1
        $sReturn = RegRead($sHKLM, $aValue[$i])
        If StringInStr($aValue[$i], "Language") Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, Chr(32)))
        GUICtrlCreateLabel($aValue[$i] & ":" & @TAB & $sReturn, 10, ($i * 20) + 10, 280, 20)
    Next
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case Else
                ;;;
        EndSwitch
    WEnd
EndFunc   ;==>_Main
Edited by smashly
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...