Snippets ( Registry ): Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
 
(Edited snippets to conform to template Snippet Header.)
 
(One intermediate revision by one other user not shown)
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__
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsRegistryExist() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
 
[[category:Snippets]]
 
{{Snippet Credit Header}}
 
== _IsRegistryExist ==
 
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 13: Line 22:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Reg_GetSID() ~ Author - [http://www.autoitscript.com/forum/user/52-geosoft/ GEOSoft] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _Reg_GetSID ==
 
{{Snippet Header
| AuthorURL = 52-geosoft
| AuthorName = GEOSoft
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 35: Line 51:
</syntaxhighlight>
</syntaxhighlight>


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _RegReadEX() ~ Author - [http://www.autoitscript.com/forum/user/35742-realm/ Realm] '''</blockquote> =====
[[#top | ReturnToContents]]
 
== _RegReadEX ==
 
{{Snippet Header
| AuthorURL = 35742-realm
| AuthorName = Realm
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
Line 47: Line 70:
     Return $var
     Return $var
EndFunc
EndFunc
</syntaxhighlight>


</syntaxhighlight>
[[#top | ReturnToContents]]

Latest revision as of 17:26, 18 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

ReturnToContents

_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()

ReturnToContents

_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

ReturnToContents