AutoIt Snippets: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
m (Converted headers to Template:Snippet Headers. If this is unacceptable, you know what to do.)
Line 6: Line 6:


== '''Examples''' ==
== '''Examples''' ==
<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>
<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.  It is only polite.'''</div>
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsInternetConnected() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness]'''</blockquote> =====
 
{{Snippet Header|_IsInternetConnected()|http://www.autoitscript.com/forum/user/35302-guinness/|guinness||}}
 
<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
ConsoleWrite("Internet Is Connected" & " = " & _IsInternetConnected() & @CRLF) ; ( Returns "True" Or "False" )
ConsoleWrite("Internet Is Connected" & " = " & _IsInternetConnected() & @CRLF) ; ( Returns "True" Or "False" )
Line 47: Line 49:
* [[Snippets ( Creation )| Snippets Creation Examples ]]
* [[Snippets ( Creation )| Snippets Creation Examples ]]


== '''AutoIt Snippets Collection''' ==


<br>
=== AutoIt <small>~ AutoIt Examples. </small> ===


== '''AutoIt Snippets Collection''' ==
===AutoIt <small>~ AutoIt Examples. </small>===
* [[Snippets ( AutoIt Audio )| Audio Related ]] ( Last Updated ~ 16:58, 21 May 2012 (BST) )
* [[Snippets ( AutoIt Audio )| Audio Related ]] ( Last Updated ~ 16:58, 21 May 2012 (BST) )
* [[Snippets ( AutoIt )| AutoIt Miscellaneous ]] ( Last Updated ~ 12:22, 1 August 2012 (BST) )
* [[Snippets ( AutoIt )| AutoIt Miscellaneous ]] ( Last Updated ~ 12:22, 1 August 2012 (BST) )
Line 58: Line 59:
* [[Snippets ( AutoIt String )| AutoIt String Related ]] ( Last Updated ~ 12:45, 1 August 2012 (BST) )
* [[Snippets ( AutoIt String )| AutoIt String Related ]] ( Last Updated ~ 12:45, 1 August 2012 (BST) )


=== GUI<small> ~ Anything GUI related. </small>===
=== GUI <small>~ Anything GUI related.</small> ===
 
* [[Snippets ( Checkboxes )| Checkboxes & Radio ]]
* [[Snippets ( Checkboxes )| Checkboxes & Radio ]]
* [[Snippets ( GUI )| GUI ]]  ( Last Updated ~ 12:11, 1 August 2012 (BST) )
* [[Snippets ( GUI )| GUI ]]  ( Last Updated ~ 12:11, 1 August 2012 (BST) )
* [[Snippets ( Graphics )| Graphics And Images ]] ( Last Updated ~ 12:37, 1 August 2012 (BST) )
* [[Snippets ( Graphics )| Graphics And Images ]] ( Last Updated ~ 12:37, 1 August 2012 (BST) )


=== Hardware <small>~ Hardware Examples </small>===
=== Hardware <small>~ Hardware Examples.</small> ===
 
* [[Snippets ( Hardware Information )| Hardware Information ]] ( Last Updated ~ 11:02, 30 April 2012 (BST) )
* [[Snippets ( Hardware Information )| Hardware Information ]] ( Last Updated ~ 11:02, 30 April 2012 (BST) )


===Numbers <small>~ Math, Number & Time Examples. </small>===
=== Numbers <small>~ Math, Number & Time Examples.</small> ===
* [[Snippets ( Math & Numbers )| Math & Numbers ]] ( Last Updated ~ 12:07, 1 August 2012 (BST) )
* [[Snippets ( Math & Numbers )| Math & Numbers ]] ( Last Updated ~ 12:07, 1 August 2012 (BST) )
* [[Snippets ( Time & Date )| Time & Date ]] ( Last Updated ~ 14:11, 21 May 2012 (BST) )
* [[Snippets ( Time & Date )| Time & Date ]] ( Last Updated ~ 14:11, 21 May 2012 (BST) )


=== Miscellaneous <small>~ All Other Examples</small>===
=== Miscellaneous <small>~ All Other Examples</small> ===
* [[Snippets ( Miscellaneous )| Miscellaneous ]] ( Last Updated ~ 12:35, 1 August 2012 (BST) )
* [[Snippets ( Miscellaneous )| Miscellaneous ]] ( Last Updated ~ 12:35, 1 August 2012 (BST) )


Line 78: Line 81:
* [[Snippets ( Wireless )|Wireless ]]
* [[Snippets ( Wireless )|Wireless ]]


===Windows <small>~ Windows Examples. </small>===
=== Windows <small>~ Windows Examples.</small> ===
* [[Snippets ( CMD ) |CMD ~ Commandline ]]
* [[Snippets ( CMD ) |CMD ~ Commandline ]]
* [[Snippets ( Files & Folders )| Files & Folders ]] ( Last Updated ~ 12:16, 1 August 2012 (BST) )
* [[Snippets ( Files & Folders )| Files & Folders ]] ( Last Updated ~ 12:16, 1 August 2012 (BST) )

Revision as of 17:58, 11 November 2012

Welcome To The AutoIt Snippets Page ~ ( Snippet - A short reusable piece of computer code )

These are generally single functions or small pieces of AutoIt code that you can add into your script which give extra functionality.

This will cover a wide variety of subjects and uses, maybe anything from finding if an internet connection is working or possibly the date Windows was installed, this page is intended to give easy access to the functions.

Examples

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

{{{AuthorName}}}








ConsoleWrite("Internet Is Connected" & " = " & _IsInternetConnected() & @CRLF) ; ( Returns "True" Or "False" )

Func _IsInternetConnected()
    Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
    If @error Then
        Return SetError(1, 0, False)
    EndIf
    Return $aReturn[0] = 0
EndFunc   ;==>_IsInternetConnected

{{{AuthorName}}}








#include <Crypt.au3>

Local $sGenericPassword_1 = 'Password@AutoIt', $sGenericPassword_2 = 'NewPassword@AutoIt', $sSavePath = @ScriptDir & '\License.dat'
ConsoleWrite('1. ' & _PasswordCrypt($sGenericPassword_1, $sSavePath) & @CRLF) ; Write the password to a file located in the @ScriptDir. The password we wrote is returned by the function.
ConsoleWrite('2. ' & _PasswordCrypt($sGenericPassword_1, $sSavePath) & @CRLF) ; Since the password has been written already, we now want to check if the user has entered the password correctly. Returns True or False.
ConsoleWrite('3. ' & _PasswordCrypt($sGenericPassword_2, $sSavePath, 1) & @CRLF) ; Overwrite the old password with a new one.
ConsoleWrite('4. ' & _PasswordCrypt($sGenericPassword_1, $sSavePath) & @CRLF) ; Check the password matches. This will fail as we're checking the old password against the new one.
FileDelete($sSavePath)

Func _PasswordCrypt($sPassword, $sFilePath, $iOverwrite = 0) ; By guinness, idea by Valuater.
    If FileExists($sFilePath) And $iOverwrite = 0 Then
        Return BinaryToString(_Crypt_DecryptData(IniRead($sFilePath, 'PasswordKey', 'Password', ''), @ComputerName, $CALG_AES_256)) == $sPassword
    Else
        If IniWrite($sFilePath, 'PasswordKey', 'Password', _Crypt_EncryptData($sPassword, @ComputerName, $CALG_AES_256)) Then
            Return $sPassword
        EndIf
    EndIf
    Return SetError(1, 0, '')
EndFunc   ;==>_PasswordCrypt

Snippet Creation Help.

AutoIt Snippets Collection

AutoIt ~ AutoIt Examples.

GUI ~ Anything GUI related.

Hardware ~ Hardware Examples.

Numbers ~ Math, Number & Time Examples.

Miscellaneous ~ All Other Examples

Networking ~ Network, Wireless and Internet Examples.

Windows ~ Windows Examples.