Jump to content

Recommended Posts

Posted (edited)

Returns the valid (short) registry key dependent on CPU architecture. You can send it all or part of the key and it shouldn't be AutoIt version dependent. If you pass it an invalid key (HKZU) then it will return an error.

;
MsgBox(0, "Test Results", _RegKey("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\"))
MsgBox(0, "Test Results", _RegKey("HKLM\SOFTWARE\Microsoft\"))

Func _RegKey($sKey)
   Local $sHold = ""
   If StringInStr($sKey, "\") Then
      $sHold = StringMid($sKey, StringInStr($sKey, "\"))
      $sKey = StringLeft($sKey, StringInStr($sKey, "\")-1)
   EndIf
   $sKey = StringReplace ($sKey, "64", "")
   $sKey = StringRegExpReplace($sKey, "(?i)^\b(HK)ey_(L|U|C)(?:.*_)?(M|U|C|R)?.*", "$1$2$3")
  ;If NOT StringRegExp($sKey, "(?i)hklm|hkcu|hkcr|hkcc|hku") Then Return SetError(1,0, $sKey & " is not a valid key name")
   If NOT StringRegExp($sKey, "(?i)hklm|hkcu|hkcr|hkcc|hku") Then Return SetError(1,0, $sKey & "")
   If @OSArch = "X64" Then $sKey &= "64"
   Return StringUpper($sKey) & $sHold
EndFunc
;

Enjoy

EDIT:

If anyone has a problem with this function please let me know and include your AutoIt version when you reply.

Tested on 3.2.13.13 and 3.3.0.0

EDIT 2:

Modified the error return to set error level to 1 and return a blank string so you can use

$Reg= _RegKey("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\")
If $Reg Then MsgBox(0, "Test Results", $Reg)
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted

Updated to a different error return. See post #1

Remember that the primary use is to return the short value of the registry hive/key and append the "64" to it if required for X64 systems.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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
×
×
  • Create New...