AutoIt Snippets: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
(Changes made to the wording of the first paragraph to improve readfability..)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Welcome To The AutoIt Snippets Page - ( '''''Snippet - A short reusable piece of computer code''''' ).   
Welcome To The AutoIt Snippets Page - ( '''''Snippet - A short reusable piece of computer code''''' ).   


Snippets are generally single functions or small pieces of AutoIt code which can be incorporated into a script to add extra functionality. This section covers a wide variety of subjects and uses. Examples may include anything from finding if an internet connection is working to retrieving the date Windows was installed. This page is intended to give easy access to the functions.
Snippets are generally single functions or small pieces of code which can be incorporated into a script to add extra functionality. This section covers a wide variety of subjects and uses. Examples may include anything from finding if an internet connection is working to retrieving the date Windows was installed. This page is intended to give easy access to the functions.


__TOC__
__TOC__
Line 14: Line 14:


{{Snippet Header
{{Snippet Header
| AuthorURL=35302-guinness
| AuthorURL=35302-guinness | AuthorName=guinness
| AuthorName=guinness
}}
}}


Line 35: Line 34:


{{Snippet Header
{{Snippet Header
| AuthorURL=4920-valuater
| AuthorURL=4920-valuater | AuthorName=Valuater
| AuthorName=Valuater
| ModifierURL=35302-guinness | ModifierName=guinness
| ModifierURL=35302-guinness
| ModifierName=guinness
}}
}}


Line 81: Line 78:
=== GUI <small>- Anything GUI related.</small> ===
=== GUI <small>- Anything GUI related.</small> ===


* [[Snippets ( Checkboxes )| Checkboxes & Radio ]]
* [[Snippets ( Checkboxes )| Checkboxes & Radio ]] ( Last Updated - 21:04, 13 November 2012 (BST) )
* [[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) )
* [[Snippets ( Combo )| Combo, Array and SQLite]] ( Last Updated - 12:37, 18 August 2015 (BST) )


=== Hardware <small>- Hardware Examples.</small> ===
=== Hardware <small>- Hardware Examples.</small> ===
Line 102: Line 100:
* [[Snippets ( Network )| Network ]] ( Last Updated - 12:33, 1 August 2012 (BST) )
* [[Snippets ( Network )| Network ]] ( Last Updated - 12:33, 1 August 2012 (BST) )
* [[Snippets ( Internet )|Internet ]] ( Last Updated - 12:30, 1 August 2012 (BST) )
* [[Snippets ( Internet )|Internet ]] ( Last Updated - 12:30, 1 August 2012 (BST) )
* [[Snippets ( Wireless )|Wireless ]]
* [[Snippets ( Wireless )|Wireless ]] ( Last Updated - 19:19, 16 November 2012 (BST) )


=== Windows <small>- Windows Examples.</small> ===
=== Windows <small>- Windows Examples.</small> ===


* [[Snippets ( CMD ) |CMD - Commandline ]]
* [[Snippets ( CMD ) |CMD - Commandline ]] (Last Updated - 19:24, 16 November 2012 (BST) )
* [[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) )
* [[Snippets ( Registry )| Registry ]]
* [[Snippets ( Registry )| Registry ]] ( Last Updated - 17:26, 18 November 2012 (BST) )
* [[Snippets ( Windows Information )| Windows Information ]] ( Last Updated - 11:27, 30 April 2012 (BST) )
* [[Snippets ( Windows Information )| Windows Information ]] ( Last Updated - 11:27, 30 April 2012 (BST) )
* [[Snippets ( Windows OS )| Windows OS ]] ( Last Updated - 14:35, 21 May 2012 (BST) )
* [[Snippets ( Windows OS )| Windows OS ]] ( Last Updated - 14:35, 21 May 2012 (BST) )

Latest revision as of 08:31, 24 May 2021

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

Snippets are generally single functions or small pieces of code which can be incorporated into a script to add extra functionality. This section covers a wide variety of subjects and uses. Examples may include anything from finding if an internet connection is working to retrieving the date Windows was installed. This page is intended to give easy access to the functions.


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


Examples

_IsInternetConnected

Author: guinness








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

ReturnToContents

_PasswordCrypt

Author: Valuater




Modified: guinness





#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

ReturnToContents

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.

  • Network ( Last Updated - 12:33, 1 August 2012 (BST) )
  • Internet ( Last Updated - 12:30, 1 August 2012 (BST) )
  • Wireless ( Last Updated - 19:19, 16 November 2012 (BST) )

Windows - Windows Examples.

Other Links

Free Software Written in AutoIt