Search the Community
Showing results for tags 'isregistrystring reg'.
-
This function will return a boolean value on whether a registry string is correctly formatted. Any suggestions for improvements then please post below. Thanks. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsRegKey ; Description ...: Check if a string is a valid registry string. ; Syntax ........: _IsRegKey($sRegistryKey) ; Parameters ....: $sRegistryKey - A registry string. ; $fFullPath - [optional] A fullpath is required. Default is False. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Modified ......: Robjong - Improved syntax as well as adding additional parameter to check against a fullpath. ; Example .......: Yes ; =============================================================================================================================== Func _IsRegKey($sRegistryKey, $fFullPath = Default) Local $sPathSRE = $fFullPath ? '+' : '*' ; Requires fullpath Return StringRegExp($sRegistryKey, '(?i)\A\h*HK(CC|CR|CU|LM|U|EY_CLASSES_ROOT|EY_LOCAL_MACHINE|EY_USERS|EY_CURRENT_(USER|CONFIG))(64)?(?:\\[^\\]*)' & $sPathSRE & '\z') = 1 EndFunc ;==>_IsRegKeyExample use of Function: Example() Func Example() _Output('HKLM', True) _Output('HKLM\', True) _Output('HKLM\Example\Test', True) _Output('HKU\Example\Test', True) _Output('HKCU\Example\Test', True) _Output('HKCR\Example\Test', True) _Output('HKCC\Example\Test', True) _Output('HKEY\Example\Test', False) ; This will return False. _Output('HKEY_LOCAL_MACHINE64\Example\Test', True) _Output('HKEY_USERS\Example\Test', True) _Output('HKEY_CURRENT_USER\Example\Test', True) _Output('HKEY_CLASSES_ROOT\Example\Test', True) _Output('HKEY_CLASSES_ROOT\Example\Test', True) _Output('HKEY_CURRENT_CONFIG\Example\Test', True) _Output('HKCR_CLASSES_ROOT\Example\Test', False) ; This will return False. _Output('HKEY_CURRENT_EXAMPLE\Example\Test', False) ; This will return False. EndFunc ;==>Example Func _Output($sString, $fExpect) Local $fResult = _IsRegKey($sString) Local $sSciTEOutput = ($fResult == $fExpect)? '+' : '!' ConsoleWrite($sSciTEOutput & ' [' & $fResult & '] ' & $sString & @CRLF) EndFunc ;==>_Output