Snippets ( Registry ): Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
 
m (+Snippets Category (+ normalize top))
Line 1: Line 1:
<div class="center" style="width:auto; margin-left:auto; margin-right:auto;">'''Please always credit an author in your script if you use their code, Its only polite.'''</div>
__TOC__
__TOC__
[[category:Snippets]]
{{Snippet Credit Header}}
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsRegistryExist() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsRegistryExist() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====



Revision as of 15:11, 12 November 2012


Please always credit an author in your script if you use their code. It is only polite.


_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