Sign in to follow this  
Followers 0
GEOSoft

Valid registry key.

3 posts in this topic

#1 ·  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!"

Share this post


Link to post
Share on other sites



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!"

Share this post


Link to post
Share on other sites

@GeoSoft

hm... its a good idea :)

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0