Snippets ( Registry )
Jump to navigation
Jump to search
_IsRegistryExist
Author: guinness
ConsoleWrite(_IsRegistryExist("HKEY_CURRENT_USER\Control Panel\Desktop", "Test") & @LF) ; False = Doesn't Exist
ConsoleWrite(_IsRegistryExist("HKEY_CURRENT_USER\Control Panel\Desktop", "CaretWidth") & @LF) ; True = Exists
Func _IsRegistryExist($sKeyName, $sValueName)
RegRead($sKeyName, $sValueName)
Return @error = 0
EndFunc ;==>_IsRegistryExist
_Reg_GetSID
Author: GEOSoft
; Returns the SID for the current user.
$sUser = _Reg_GetSID()
If $sUser Then MsgBox(0, "RESULTS", $sUser)
Func _Reg_GetSID()
Local $sKey = "HKU\", $sEntry, $iReg = 1, $sRegEx = "(?i)s-1-5-21-([\d|-]*)"
While 1
$sEntry = RegEnumKey($sKey, $iReg)
If @Error Then ExitLoop
$iReg += 1
If NOT StringRegExp($sEntry, $sRegEx) Then ContinueLoop
Local $aRegExp = StringRegExp($sEntry, $sRegEx, 1)
Return $aRegExp[0]
Wend
Return False
EndFunc;<==> _Reg_GetSID()
_RegReadEX
Author: Realm
; Returns default error message and code if key is missing
ConsoleWrite( 'Program Files Directory= ' & _RegReadEX( 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion', 'ProgramFilesDir', '<Key is not present>') & @LF)
ConsoleWrite( 'Default Return= ' & _RegReadEX( 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion', 'A Missing Key Test', '<Key is not present>') & ' Error= ' & @error & @LF)
Func _RegReadEX($sKeyName, $sValueName, $sDefault)
Local $var = RegRead($sKeyName, $sValueName)
If @error Then Return SetError(@error,0,$sDefault)
Return $var
EndFunc