Jump to content
Sign in to follow this  
Jon

Examples wanted

Recommended Posts

I want some nice examples for the release. Mainly for GUI stuff but anything is fine. Just post the scripts here and fill in the "template" bit at the top that you get when you do "file \ new" (author name, function, etc). Very simple as well as advanced stuff is welcome. Someone else might want to suggest a list of things that would be useful.

Bear in mind that the examples used will have to be nicely written and well commented - people might learn from these! I wouldn't want to try and code a GUI script without seeing something first.

Share this post


Link to post
Share on other sites

Here is an example that enables you to remove entries from your IE Typed URL History.. (IE needs to be closed for proper updating )
 

; autoit version: 3.0
; language:    english
; author:        jos van der zande
; Date: November 09, 2004
;
; script function: Show current IE "Typed URL history" and enables you to remove selected entries.
;IE needs to be closed or else your update is gone after closing IE. 
;
#include <GUIConstants.au3>
; Variable definitions
Global $s_URLSite            ;Save field
Global $h_URLSite[26]        ;Array with the GUI Handles for URL History entries
Global $h_URLSite_CheckBox[26];Array with the GUI Handels for URL History Checkboxes
Global $H_Update, $H_Cancel   ;Handles for Buttons
Global $BaseX = 5            ;Base X coordinate
Global $BaseY = -5          ;Base Y coordinate
Global $x,$y,$rc              ;helper variables
;
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------
Opt ("GUICoordMode", 1)
GUICreate("Configure IE Typed history.  ", 400, 600)
; Create 25 Checkboxes and labels for each URL Typed Hustory Reg entry
For $x = 1 To 25
; read the registry entry
    $s_URLSite = RegRead("HKCU\Software\Microsoft\Internet Explorer\TypedURLs", "url" & $x)
; Create check box
    $h_URLSite_CheckBox[$x] = GUICtrlCreateCheckbox("", $BaseX, $BaseY + 20 * $x, 20, 20)
; Check the Checkbox if this registry entry contains text
    If $s_URLSite <> "" Then GUICtrlSetState($h_URLSite_CheckBox[$x], 1)
; show the registry content in a lable
    $h_URLSite[$x] = GUICtrlCreateLabel($s_URLSite, $BaseX + 25, $BaseY + 20 * $x, 350, 20)
Next
; Show update button and close button
$H_Update = GUICtrlCreateButton("Update", 140, 550)
; set the text when hover over the Update button
GUICtrlSetTip(-1, "Save all changes made to Registry")
$H_Cancel = GUICtrlCreateButton("Cancel", 210, 550)
; set the text when hover over the Cancel button
GUICtrlSetTip(-1, "Exit and ignore all changes made")
; Show the GUI
GUISetState(@SW_SHOW)
; Process GUI Input
;-------------------------------------------------------------------------------------------
While 1
; Get message from gui
    $RC = GUIGetMsg()
; Exit script when GUI is closed
    If $RC = $GUI_EVENT_CLOSE Then Exit
; Exit script when Cancel button is clicked
    If $RC = $H_Cancel Then Exit
; update registry with only the selected URL entries in the rigth sequence
    If $RC = $H_Update Then
        If 6 = MsgBox(4, 'Update registry', 'Sure you want to update the registry ?') Then
            $y = 1
            For $x = 1 To 25
                If GUICtrlRead($h_URLSite_CheckBox[$x]) = 1 Then
                    RegWrite("HKCU\Software\Microsoft\Internet Explorer\TypedURLs", "url" & $y, "REG_SZ", GUICtrlRead($h_URLSite[$x]))
                    $y = $y + 1
                EndIf
            Next
            For $x = $y To 25
                RegDelete("HKCU\Software\Microsoft\Internet Explorer\TypedURLs", "url" & $x)
            Next
        EndIf
        Exit
    EndIf
WEnd
Exit
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

damn.. mines not quite as good as the one above lol, but i thought "Sleep" could have a better example. :idiot:

;===============================================================================
;
; Function Name:    Sleep ( delay )
; Description:    Pause's execution of a script until the given time has expired.
; Parameter(s):  Delay - Amount of time to pause (in milliseconds). 
; Requirement(s):   Delay Input.
; Return Value(s):  In example's a MsgBox is returned.
;
;===============================================================================

;Simple Example:

Sleep(5000); Pause's script until five seconds have past.
MsgBox(0, "Time Expired", "Five seconds have past.")

;Advanced Example:

$TimeInMS = InputBox("Input Time", "Enter the amount of time to sleep for in seconds.")
; Stores the time entered (in seconds)
$TimeInS = $TimeInMS * 1000 
; Converts the time into milliseconds
Sleep($TimeInS)
; Pause's script until time has past.
MsgBox(0, "Time Expired", "The " & $TimeInMS & " seconds have past.")
Edited by buzz44

qq

Share this post


Link to post
Share on other sites

Here's one.

;====================================================
;================= Example of a GUI =================
;====================================================
; AutoIt version: 3.0.103
; Language:    English
; Author:        "SlimShady"
;
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------

;Include constants
#include <GUIConstants.au3>

;Initialize variables
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 300
$GUIHeight = 250

;Create window
GUICreate("New GUI", $GUIWidth, $GUIHeight)

;Create an edit box with no text in it
$Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190)

;Create an "OK" button
$OK_Btn = GUICtrlCreateButton("OK", 75, 210, 70, 25)

;Create a "CANCEL" button
$Cancel_Btn = GUICtrlCreateButton("Cancel", 165, 210, 70, 25)

;Show window/Make the window visible
GUISetState(@SW_SHOW)

;Loop until:
;- user presses Esc
;- user presses Alt+F4
;- user clicks the close button
While 1
  ;Pause a bit so the script doesn't use alot of CPU time
   Sleep(25)
  ;After every loop check if the user clicked something in the GUI window
   $msg = GUIGetMsg()

   Select
   
     ;Check if user clicked on the close button
      Case $msg = $GUI_EVENT_CLOSE
        ;Destroy the GUI including the controls
         GUIDelete()
        ;Exit the script
         Exit
         
     ;Check if user clicked on the "OK" button
      Case $msg = $OK_Btn
         MsgBox(64, "New GUI", "You clicked on the OK button!")
      
     ;Check if user clicked on the "CANCEL" button
      Case $msg = $Cancel_Btn
         MsgBox(64, "New GUI", "You clicked on the Cancel button!")
         
   EndSelect

WEnd

Here's another one:

;====================================================
;============= Example of a child window ============
;====================================================
; AutoIt version: 3.0.103
; Language:    English
; Author:        "SlimShady"
;
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------

;Include constants
#include <GUIConstants.au3>
;Change the WinTitleMatchMode for the demonstration
AutoItSetOption("WinTitleMatchMode", 4)

;Initialize variables
Global $IniFile
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 250
$GUIHeight = 250

;Create main/parent window
$ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight)
;Save the position of the parent window
$ParentWin_Pos = WinGetPos($ParentWin, "")
;Show the parent window/Make the parent window visible
GUISetState(@SW_SHOW)

;Create child window and add the parameter to make it the child of the parent window
$ChildWin = GUICreate("Child GUI", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin)
;Show the child window/Make the child window visible
GUISetState(@SW_SHOW)

;Switch to the parent window
GUISwitch($ParentWin)

;Loop until:
;- user presses Esc when focused to the parent window
;- user presses Alt+F4 when focused to the parent window
;- user clicks the close button of the parent window
While 1
  ;Pause a bit so the script doesn't use alot of CPU time
   Sleep(25)
  ;After every loop check if the user clicked something in the GUI windows
   $msg = GUIGetMsg(1)
   Select
     ;Check if user clicked on a close button of any of the 2 windows
      Case $msg[0] = $GUI_EVENT_CLOSE
        ;Check if user clicked on the close button of the child window
         If $msg[1] = $ChildWin Then
            MsgBox(64, "Test", "Child GUI will now close.")
           ;Switch to the child window
            GUISwitch($ChildWin)
           ;Destroy the child GUI including the controls
            GUIDelete()
        ;Check if user clicked on the close button of the parent window
         ElseIf $msg[1] = $ParentWin Then
            MsgBox(64, "Test", "Parent GUI will now close.")
           ;Switch to the parent window
            GUISwitch($ParentWin)
           ;Destroy the parent GUI including the controls
            GUIDelete()
           ;Exit the script
            Exit
         EndIf

   EndSelect

WEnd
Edited by SlimShady

Share this post


Link to post
Share on other sites

Simple script that show list of icons in the given file. It show icon index which can be used in GUICtrlCreateIcon function.

;===============================================================================
;
; Description:    Show all icons in the given file
; Requirement(s):   Autoit 3.0.103+
; Author(s):        YDY (Lazycat)
;
;===============================================================================

#include <GUIConstants.au3>

; Setting variables
Global $ahIcons[30], $ahLabels[30] 
Global $iStartIndex = 0, $iCntRow, $iCntCol, $iCurIndex
Global $sFilename = @SystemDir & "\shell32.dll"; Default file is "shell32.dll"

; Creating GUI and controls
GUICreate("Icon Selector", 385, 435, @DesktopWidth/2 - 192,_
@DesktopHeight/2 - 235, -1, $WS_EX_ACCEPTFILES)
GUICtrlCreateGroup("", 5, 1, 375, 40)
GUICtrlCreateGroup("", 5, 50, 375, 380)
$hFile = GUICtrlCreateEdit($sFilename, 12,  15, 325, 16, $ES_READONLY, $WS_EX_STATICEDGE)
GUICtrlSetCursor(-1, 2) 
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUICtrlSetTip(-1, "You can drop files from shell here...")
$hFileSel = GUICtrlCreateButton("...", 345,  14, 26, 18)
$hPrev = GUICtrlCreateButton("Previous", 10,  45, 60, 24, $BS_FLAT)
GUICtrlSetState(-1, $GUI_DISABLE)
$hNext = GUICtrlCreateButton("Next", 75,  45, 60, 24, $BS_FLAT)

; This code build two arrays of ID's of icons and labels for easily update
For $iCntRow = 0 to 4
    For $iCntCol = 0 to 5
        $iCurIndex = $iCntRow * 6 + $iCntCol
        $ahIcons[$iCurIndex] = GUICtrlCreateIcon($sFilename, $iCurIndex,_
        60 * $iCntCol + 25, 70 * $iCntRow + 80)
        $ahLabels[$iCurIndex] = GUICtrlCreateLabel($iCurIndex,_
        60 * $iCntCol+11, 70 * $iCntRow + 115, 60, 20, $SS_CENTER)
    Next
Next

GUISetState()

While 1
    $iMsg = GUIGetMsg()
   ; Code below will check if the file is dropped (or selected)
    $sCurFilename = GUICtrlRead($hFile) 
    If $sCurFilename <> $sFilename Then
        $iStartIndex = 0
        $sFilename = $sCurFilename
        _GUIUpdate()
    Endif
   ; Main "Select" statement that handles other events
    Select
        Case $iMsg = $hFileSel
            $sTmpFile = FileOpenDialog("Select file:",_
            "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",_
            "Executables & dll's (*.exe;*.dll;*.ocx;*.icl)")
            If @error Then ContinueLoop
            GUICtrlSetData($hFile, $sTmpFile); GUI will be updated at next iteration
        Case $iMsg = $hPrev
            $iStartIndex = $iStartIndex - 30
            _GUIUpdate()
        Case $iMsg = $hNext
            $iStartIndex = $iStartIndex + 30
            _GUIUpdate()
        Case $iMsg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
Wend
    
; Just updates GUI icons, labels and set state of "Previous" button
Func _GUIUpdate() 
    For $iCntRow = 0 to 4
        For $iCntCol = 0 to 5
            $iCurIndex = $iCntRow * 6 + $iCntCol
            GUICtrlSetImage($ahIcons[$iCurIndex], $sFilename, $iCurIndex + $iStartIndex)
            GUICtrlSetData($ahLabels[$iCurIndex], $iCurIndex + $iStartIndex)
        Next
    Next
   ; This is because we don't want negative values
    If $iStartIndex = 0 Then
        GUICtrlSetState($hPrev, $GUI_DISABLE)
    Else
        GUICtrlSetState($hPrev, $GUI_ENABLE)
    Endif       
EndFunc

Edit: fixed wordwrap

Edited by Lazycat

Share this post


Link to post
Share on other sites

Here is one that simply shows how a gui BASICALLY works. It shows alot of system information and important folder directorys. It shows the use of macros and functions very well.

#include <GuiConstants.au3>
#trayiconhide

If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("Computer Information - By : Para", 469, 639,(@DesktopWidth-469)/2, (@DesktopHeight-639)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$VOL = DriveGetLabel("C:\")
$SERIAL = DriveGetSerial("C:\")
$TOTAL = DriveSpaceTotal("C:\")
$FREE = DriveSpaceFree("C:\")

$ComputerName = GuiCtrlCreateLabel("Computer Name", 10, 10, 150, 20)
$CurrentUserName = GuiCtrlCreateLabel("Current User Name", 10, 40, 150, 20)
$Operatingsystem = GuiCtrlCreateLabel("Operating System", 10, 70, 150, 20)
$ServicePack = GuiCtrlCreateLabel("Service Pack", 10, 100, 150, 20)
$VolumeLabel = GuiCtrlCreateLabel("C: Volume Label", 10, 130, 150, 20)
$SerialNumber = GuiCtrlCreateLabel("C: Serial Number", 10, 160, 150, 20)
$TotalSpace = GuiCtrlCreateLabel("C: Total Space", 10, 190, 150, 20)
$FreeSpace = GuiCtrlCreateLabel("C: Free Space", 10, 220, 150, 20)
$IpAddress = GuiCtrlCreateLabel("Ip Address", 10, 250, 150, 20)
$StartupDirectory = GuiCtrlCreateLabel("Startup Directory", 10, 280, 150, 20)
$WindowsDirectory = GuiCtrlCreateLabel("Windows Directory", 10, 310, 150, 20)
$SystemFolderDirectory = GuiCtrlCreateLabel("System Folder Directory", 10, 340, 150, 20)
$DesktopDirectory = GuiCtrlCreateLabel("Desktop Directory", 10, 370, 150, 20)
$MyDocumentsDirectory = GuiCtrlCreateLabel("My Documents Directory", 10, 400, 150, 20)
$ProgramFileDirectory = GuiCtrlCreateLabel("Program File Directory", 10, 430, 150, 20)
$StartMenuDirectory = GuiCtrlCreateLabel("Start Menu Directory", 10, 460, 150, 20)
$DesktopWidth = GuiCtrlCreateLabel("Desktop Width (Pixels)", 10, 520, 150, 20)
$TemporaryFileDirectory = GuiCtrlCreateLabel("Temporary File Directory", 10, 490, 150, 20)
$DesktopHeight = GuiCtrlCreateLabel("Desktop Height (Pixels)", 10, 550, 150, 20)
$Date = GuiCtrlCreateLabel("Date", 10, 580, 150, 20)
$Time = GuiCtrlCreateLabel("Time", 10, 610, 150, 20)
$Input_ComputerName = GuiCtrlCreateInput("" & @ComputerName, 180, 10, 280, 20)
$Input_CurrentUserName = GuiCtrlCreateInput("" & @UserName, 180, 40, 280, 20)
$Input_OperatingSystem = GuiCtrlCreateInput("" & @OSTYPE, 180, 70, 280, 20)
$Input_ServicePack = GuiCtrlCreateInput("" & @OSServicePack, 180, 100, 280, 20)
$Input_VolumeLabel = GuiCtrlCreateInput("" & $VOL, 180, 130, 280, 20)
$Input_SerialNumber = GuiCtrlCreateInput("" & $SERIAL, 180, 160, 280, 20)
$Input_TotalSpace = GuiCtrlCreateInput("" & $TOTAL, 180, 190, 280, 20)
$Input_FreeSpace = GuiCtrlCreateInput("" & $FREE, 180, 220, 280, 20)
$Input_IpAddress = GuiCtrlCreateInput("" & @IPAddress1, 180, 250, 280, 20)
$Input_StartupDirectory = GuiCtrlCreateInput("" & @StartupDir, 180, 280, 280, 20)
$Input_WindowsDirectory = GuiCtrlCreateInput("" & @WindowsDir, 180, 310, 280, 20)
$Input_SystemFolderDirectory = GuiCtrlCreateInput("" & @SystemDir, 180, 340, 280, 20)
$Input_DesktopDirectory = GuiCtrlCreateInput("" & @DesktopDir, 180, 370, 280, 20)
$Input_MyDocumentsDirectory = GuiCtrlCreateInput("" & @MyDocumentsDir, 180, 400, 280, 20)
$Input_ProgramFilesDirectory = GuiCtrlCreateInput("" & @ProgramFilesDir, 180, 430, 280, 20)
$Input_StartMenuDirectory = GuiCtrlCreateInput("" & @StartMenuDir, 180, 460, 280, 20)
$Input_TemporaryFileDirectory = GuiCtrlCreateInput("" & @TempDir, 180, 490, 280, 20)
$Input_DesktopWidth = GuiCtrlCreateInput("" & @DesktopWidth, 180, 520, 280, 20)
$Input_DesktopHeight = GuiCtrlCreateInput("" & @DesktopHeight, 180, 550, 280, 20)
$Input_Date = GuiCtrlCreateInput("(MONTH)(DAY)(YEAR) " & @MON & "-" & @MDAY & "-" & @YEAR, 180, 580, 280, 20)
$Input_Time = GuiCtrlCreateInput("(HOUR)(MIN)(SEC) " & @HOUR &  ":" & @MIN & ":" & @SEC, 180, 610, 280, 20)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit
Edited by para

Share this post


Link to post
Share on other sites

My Contribution to the cause:

; autoit version: 3.0
; language:       English
; author:         Larry Bailey
; email:          psichosis@tvn.net
; Date: November 15, 2004
;
; Script Function
; Creates a GUI based dice rolling program
; using the Random function

#include <GUIConstants.au3>

GUICreate("Dice Roller", 265, 150, -1, -1)

$button1= GUICtrlCreateButton("D2", 5, 25, 50, 30)
$button2= GUICtrlCreateButton("D3", 65, 25, 50, 30)
$button3= GUICtrlCreateButton("D4", 125, 25, 50, 30)
$button4= GUICtrlCreateButton("D6", 5, 65, 50, 30)
$button5= GUICtrlCreateButton("D8", 65, 65, 50, 30)
$button6= GUICtrlCreateButton("D10", 125, 65, 50, 30)
$button7= GUICtrlCreateButton("D12", 5, 105, 50, 30)
$button8= GUICtrlCreateButton("D20", 65, 105, 50, 30)
$button9= GUICtrlCreateButton("D100", 125, 105, 50, 30)
$button10= GUICtrlCreateButton("Clear Dice", 185, 105, 65, 30) 
$output = GUICtrlCreateLabel("", 185, 45, 70, 50, 0x1000)
$die = GUICtrlCreateLabel("", 185, 25, 70, 20, 0x1000)
GUICtrlSetFont($output, 24, 800, "", "Comic Sans MS")

GuiSetState ()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
       Select
         Case $msg = $button1
             $results = Random(1,2, 1)
             $results = "  " & $results
             GUICtrlSetData($output, $results)
             GUICtrlSetData($die, "2 Sided Die")
         Case $msg = $button2
             $results = Random(1,4)
             $results = Int($results)
             $results = "  " & $results
             GUICtrlSetData($output, $results)
             GUICtrlSetData($die, "3 Sided Die")
          Case $msg = $button3
             $results = Random(1,4, 1)
             $results = "  " & $results
             GUICtrlSetData($output, $results)
             GUICtrlSetData($die, "4 Sided Die")
         Case $msg = $button4
             $results = Random(1,6, 1)
             $results = "  " & $results
             GUICtrlSetData($output, $results)
             GUICtrlSetData($die, "6 Sided Die")
         Case $msg = $button5
             $results = Random(1,8)
             $results = "  " & $results
             GUICtrlSetData($output, $results)
             GUICtrlSetData($die, "8 Sided Die")
         Case $msg = $button6
             $results = Random(1,10, 1)
               If $results < 10 Then $results = "  " & $results
                   If $results > 9 Then $results = " " & $results
             GUICtrlSetData($output, $results)
             GUICtrlSetData($die, "10 Sided Die")
         Case $msg = $button7
             $results = Random(1,12, 1)
               If $results < 10 Then $results = "  " & $results
                   If $results > 9 Then $results = " " & $results
            GUICtrlSetData($output, $results)
            GUICtrlSetData($die, "12 Sided Die")
         Case $msg = $button8
            $results = Random(1,20, 1)
              If $results < 10 Then $results = "  " & $results
                  If $results > 9 Then $results = " " & $results
             GUICtrlSetData($output, $results)
             GUICtrlSetData($die, "20 Sided Die")
         Case $msg = $button9
             $results = Random(1,100, 1)
              If $results <10 Then $results = "  " & $results
                   If $results > 9 and $results < 100 Then $results = " " & $results
             GUICtrlSetData($output, $results)
             GUICtrlSetData($die, "100 Sided Die")
          Case $msg = $button10
             GUICtrlSetData($output, "")
             GUICtrlSetData($die, "")
      EndSelect
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Edited by sykes

We have enough youth. How about a fountain of SMART?

Share this post


Link to post
Share on other sites

Another Contribution

; AutoIt Version 3.0.103
; Language:    English
; Author:        Larry Bailey
; Email:          psichosis@tvn.net
; Date: January 11, 2005
;
; Script Function
; Creates a simple GUI showing the use of
; a label, a combobox and a button
; Selecting an item from the combobox
; and clicking the button updates the label text

#include <GuiConstants.au3>

Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000

; Create the GUI window and controls
GuiCreate("MyGUI", 191, 157,(@DesktopWidth-191)/2, (@DesktopHeight-157)/2)
$Label_1 = GuiCtrlCreateLabel("Label1", 30, 40, 131, 21, 0x1000)
$Combo_2 = GuiCtrlCreateCombo("", 30, 60, 130, 21)
GuiCtrlSetData($combo_2, "Item1|Item2|Item3|Item4|Item5")
$button1 = GuiCtrlCreateButton("Set Label", 30, 90, 130, 20)

; Run the GUI until it is closed
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    ;When button is pressed, label text is changed
    ;to combobox value
    Case $msg = $button1
      $data = GUICtrlRead($Combo_2)
      GuiCtrlSetData($Label_1, $data)
    EndSelect
WEnd
Exit

We have enough youth. How about a fountain of SMART?

Share this post


Link to post
Share on other sites

my 0,02 illustrating resizing and drag and drop on input control.

Perhaps a complete replacement of inputBox function (french joke) :idiot:

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0.103
; Language:    English
; Platform:    WinXP
; Author:       J-Paul Mesnage <jpaul-mesnage at ifrance com>
; Script Function
; Personalized inputBox with GUI functions.
;
; Version:
;    1.0    Initial release
;
; ----------------------------------------------------------------------------

#include <Constants.au3>
#include <GUIConstants.au3>

AutoItSetOption("GUICoordMode", 2)

; start the definition accepting dropfile on the input control, displayed on the center of the screen
GuiCreate ("My InputBox",190,114,-1,-1, BitOr($WS_SIZEBOX,$WS_SYSMENU), $WS_EX_ACCEPTFILES)
GuiSetIcon ("Eiffel Tower.ico")

GuiSetFont (8,-1,-1,"Arial")

; add prompt info
GuiCtrlCreateLabel ("Prompt", 8,7)
GuiCtrlSetResizing (-1,$GUI_DOCKLEFT+$GUI_DOCKTOP)

; add the input area
$idEdit = GuiCtrlCreateInput ("Default", -1,3,175,20,$ES_PASSWORD)
GuiCtrlSetResizing (-1,$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
GuiCtrlSetState (-1,$GUI_FOCUS)

; add the button that will close the GUI
$idOk = GuiCtrlCreateButton ("OK",-1,3,75,24)
GuiCtrlSetResizing (-1,$GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKVCENTER)
GuiCtrlSetState (-1,$GUI_DEFBUTTON)

; add the button that will close the GUI
$idCancel = GuiCtrlCreateButton ("Cancel", 25,-1)
GuiCtrlSetResizing (-1,$GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKVCENTER)

; display the GUI
GuiSetState()


; Run the GUI until the dialog is closed or timeout
$start=TimerInit()
do
$msg = GUIGetMsg()
    Select
    case $msg = $idEdit or $msg = $idOK or $msg = $idCancel
        exitloop
    case $msg>0
        $start=TimerInit()
    EndSelect
until $msg = $GUI_EVENT_CLOSE Or TimerDiff($start) >= 5000; timeout = 5 sec

if $msg <> $idCancel then      ; to verify if OK was click
        $input = GuiCtrlRead ($idEdit); get the type value
        msgbox(0,"Result", $input, 2); will display the typed value
endif

EDIT Thanks Josbe for pointing out my bad replace in the fly of a working script

Edited by jpm

Share this post


Link to post
Share on other sites

Straight out of the helpfile from my encryption func, Ready and roaring!:

;====================================================
;============= Encryption Tool With GUI ============= 
;====================================================
; AutoIt version: 3.0.103
; Language:       English
; Author:         "Wolvereness"
;
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------
#include <guiconstants.au3>
#include <string.au3>
;#include files for encryption and GUI constants
;~~
$WinMain = GuiCreate('Encryption tool', 400, 400)
; Creates window
;~~
$EditText = GuiCtrlCreateEdit('',5,5,380,350)
; Creates main edit
;~~
$InputPass = GuiCtrlCreateInput('',5,360,100,20, 0x21)
; Creates the password box with blured/centered input
;~~
$InputLevel = GuiCtrlCreateInput(1, 110, 360, 50, 20, 0x2001)
$UpDownLevel = GUICtrlSetLimit(GuiCtrlCreateUpDown($inputlevel),10,1)
; These two make the level input with the Up|Down ability
;~~
$EncryptButton = GuiCtrlCreateButton('Encrypt', 170, 360, 105, 35)
$DecryptButton = GuiCtrlCreateButton('Decrypt', 285, 360, 105, 35)
; Encryption/Decryption buttons
;~~
GUICtrlCreateLabel('Password', 5, 385)
GuiCtrlCreateLabel('Level',110,385)
; Simple text labels so you know what is what
;~~
GuiSetState()
; Shows window
;~~

Do
   $Msg = GuiGetMsg()
   If $msg = $EncryptButton Then
     ; When you press Encrypt
     ;~~
      GuiSetState(@SW_DISABLE,$WinMain)
     ; Stops you from changing anything
     ;~~
      $string = GuiCtrlRead($EditText)
     ; Saves the editbox for later
     ;~~
      GUICtrlSetData($EditText,'Please wait while the text is Encrypted/Decrypted.')
     ; Friendly message
     ;~~
      GuiCtrlSetData($EditText,_StringEncrypt(1,$string,GuiCtrlRead($InputPass),GuiCtrlRead($InputLevel)))
     ; Calls the encryption. Sets the data of editbox with the encrypted string
     ;~~
      GuiSetState(@SW_ENABLE,$WinMain)
     ; This turns the window back on
     ;~~
   EndIf
   If $msg = $DecryptButton Then
     ; When you press Decrypt
     ;~~
      GuiSetState(@SW_DISABLE,$WinMain)
     ; Stops you from changing anything
     ;~~
      $string = GuiCtrlRead($EditText)
     ; Saves the editbox for later
     ;~~
      GUICtrlSetData($EditText,'Please wait while the text is Encrypted/Decrypted.')
     ; Friendly message
     ;~~
      GuiCtrlSetData($EditText,_StringEncrypt(0,$string,GuiCtrlRead($InputPass),GuiCtrlRead($InputLevel)))
     ; Calls the encryption. Sets the data of editbox with the encrypted string
     ;~~
      GuiSetState(@SW_ENABLE,$WinMain)
     ; This turns the window back on
     ;~~
   EndIf
Until $msg = $GUI_EVENT_CLOSE; Continue loop untill window is closed
Edited by Wolvereness

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Share this post


Link to post
Share on other sites

This is my Lidel Script :idiot:

; ----------------------------------------------------------------------------
;
; AutoIt Version:    3.0
; Language:        Germany
; Platform:        Win9x / NT/XP
; Author:            DirtyBanditos <DirtyBanditos@web.de.>
; Website Autor    www.Dirtybanditos.de
; Releas Date :    31.12.2004
;Template AutoIt script.
;
;===============================================================================
; ----------------------------------------------------------------------------
; Set up our defaults
; ----------------------------------------------------------------------------
;AutoItSetOption("MustDeclareVars", 1)
;AutoItSetOption("MouseCoordMode", 0)
;AutoItSetOption("PixelCoordMode", 0)
;AutoItSetOption("RunErrorsFatal", 1)
;AutoItSetOption("TrayIconDebug", 1)
;AutoItSetOption("WinTitleMatchMode", 4)
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------
#include <GUIConstants.au3>
Func _MouseWrap()
   While 1
      $pos = MouseGetPos()
      If $pos[0] < 2 Then MouseMove(@DesktopWidth - 2, $pos[1], 1)
      If $pos[0] > @DesktopWidth - 2 Then MouseMove(2, $pos[1], 1)
      If $pos[1] < 2 Then MouseMove($pos[0], @DesktopHeight - 2, 1)
      If $pos[1] > @DesktopHeight - 2 Then MouseMove($pos[0], 2, 1)
   Wend
EndFunc  ;==>_MouseWrap
GUICreate("DirtyBanditos Automated Link Starter Version 1.0 Coded 2004-2005 !!!Nutze Die Pfeiltasten Deines  Keyboardes  Hoch und Runter dan Return Fertig!!!", 900, 470, -1, -1, "Arial Black")
GUISetBkColor(0x000000)
GUICtrlCreateLabel("DirtyBanditos  Automated Link Starter Version 1.0 Coded 2004-2005 !!!  Nutze Die Pfeiltasten Deines  Keyboardes  Hoch und Runter dan Return Fertig!!!Drücke Esc Für Quit", 75, 10, 600, 300)
GUICtrlSetColor(-1, 0xffff0090)
GUICtrlSetFont(-1, 14, 40)
GUICtrlCreateLabel("DirtyBanditos 2004-2005", 680, 40, 300, 300)
GUICtrlSetColor(-1, 0xff33FF33)
GUICtrlSetFont(-1, 10, 10)
GUISetFont(10, 400, 0, "Arial Black")
;$MyList = GUICtrlCreateList ("Arial Black", 25, 50, 750, 240)
$MyList = GUICtrlCreateList("", 25, 90, 850, 320, $LBS_USETABSTOPS)
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!1" & @TAB & "http://www.bigdragon.6x.to/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!2" & @TAB & "http://www.hiddensoft.com/forum")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!3" & @TAB & "http://www.SacredShop.de.vu")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!4" & @TAB & "http://www.gamecopyworld.com")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!5" & @TAB & "http://www.battleforums.com/showthread.php?s=&threadid=52718")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!6" & @TAB & "http://world.altavista.com/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!7" & @TAB & "http://www.blizzhackers.com/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!8" & @TAB & "http://www.iconarchive.com/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!9" & @TAB & "http://suprnova.org")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!10" & @TAB & "http://sacred-game.com/index.php")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!11" & @TAB & "http://sourceforge.net/index.php")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!12" & @TAB & "http://www.sofort-mail.de/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!13" & @TAB & "http://www.wardriving-forum.de/phpBB2/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!14" & @TAB & "http://www.hiddensoft.com")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!15" & @TAB & "http://www.voidofmind.com/eedok/gamepage.php?id=tuts")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!16" & @TAB & "http://www.gametutorials.com/CodeDump/CodeDump_Pg1.htm")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!17" & @TAB & "http://www.coding-board.de/board/showthread.php?t=6")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!18" & @TAB & "http://tejo.yourdotstore.com/~diablo.com/links.htm")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!19" & @TAB & "http://go.to/Hairy_Bits")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!20" & @TAB & "http://win32asm.cjb.net")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!21" & @TAB & "http://www.icq.com")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!22" & @TAB & "http://sacred.ingame.de/itemdb/index.php?mod=suchform")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!23" & @TAB & "http://ollyscript.apsvans.com")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!24" & @TAB & "http://www.online-tutorials.net/hacking--cracking/speicherzugriff-tutorial-teil-1/tutorials-t-27-63.html")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!25" & @TAB & "http://www.brzi.cjb.net")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!26" & @TAB & "http://www.freenet.de/freenet")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!27" & @TAB & "http://cip.myz.info/index.php?page=links")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!28" & @TAB & "http://www.codingcommunity.de/megatoplist/index.html")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!29" & @TAB & "http://tutorials.accessroot.com")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!30" & @TAB & "http://membres.lycos.fr/tsearch")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!31" & @TAB & "http://www.ragnarokonline.de/news285.htm")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!32" & @TAB & "http://www.dday-info.de")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!33" & @TAB & "http://www.nic.de.vu")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!34" & @TAB & "http://www.protools.cjb.net")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!35" & @TAB & "http://y0da.cjb.net")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!36" & @TAB & "http://www.cheaters-guild.com/cheat-index.asp?category=HexCheats")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!37" & @TAB & "http://www.bloodshed.net/dev/devcpp.html")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!38" & @TAB & "http://zor.org/krobar")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!39" & @TAB & "http://upx.sourceforge.net")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!40" & @TAB & "http://www.fuckinworld.org/active85k/frames.htm")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!41" & @TAB & "http://www.exetools.com/forum/showthread.php?t=4691")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!42" & @TAB & "http://www.c-plusplus.de/compiler.htm")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!43" & @TAB & "https://freemailng2102.web.de/msg/notallowed.htm?reason=security")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!44" & @TAB & "http://www.buha.info/files/user/html/main_Tools.html")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!45" & @TAB & "http://bcx.basicguru.com")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!46" & @TAB & "http://www.wireless-nrw.de/?link=downloads")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!47" & @TAB & "http://perso.wanadoo.fr/manus-magnus")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!48" & @TAB & "http://www.dhp64.fatal.ru/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!49" & @TAB & "http://www.bitrock.com/download_download.html")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!50" & @TAB & "http://freshmeat.net")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!51" & @TAB & "http://www.tvtorrents.tv")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!52" & @TAB & "http://www.bi-torrent.com/index.htm")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!53" & @TAB & "http://members.lycos.nl/bt4u/index.php")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!54" & @TAB & "http://10mbit.com")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!55" & @TAB & "http://www.ddlboard.com/index.php")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!56" & @TAB & "http://www.escom.biz/bt/index.php")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!57" & @TAB & "http://www.filelist.org/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!58" & @TAB & "http://oasis.bscn.com/torrents/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!59" & @TAB & "http://www.IrcSpy.com/search.asp")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!60" & @TAB & "http://isohunt.com/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!61" & @TAB & "http://www.lokitorrent.com/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!62" & @TAB & "http://searchto01.epsylon.org/index.php")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!63" & @TAB & "http://www.torrentsearch.com/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!64" & @TAB & "http://torrentreactor.net/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!65" & @TAB & "http://www.torrents.co.uk/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!66" & @TAB & "http://www.torrentspy.com/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!67" & @TAB & "http://www.btefnet.net/index.php")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!68" & @TAB & "http://www.crackz-serialz.com/list/d/12  download for delphi 7")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!69" & @TAB & "www.4programmers.net ")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!70" & @TAB & "ftp://uoo.univ.szczecin.pl/disk2/ftp/pub/programow/delphi/delphi7p.exe")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!71" & @TAB & "http://www.torrentspy.com/")
GUICtrlSetData($MyList, "DirtysBanditos Top Seiten!72" & @TAB & "http://einz.freeserverhost.com/czat.zip ") 


$OpenURL = GUICtrlCreateButton("Open", 25, 395, 100, 30, $BS_DEFPUSHBUTTON)
GUICtrlSetState($OpenURL, $GUI_DISABLE)
$Close = GUICtrlCreateButton("Close", 675, 395, 100, 30)
GUISetState()
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
   $msg = GUIGetMsg()
   If GUICtrlGetState($OpenURL) <> $GUI_ENABLE And GuiCtrlRead ($MyList) <> "" Then
      GUICtrlSetState($OpenURL, $GUI_ENABLE)
      GUICtrlSetFont($OpenURL, 9, 800)
   EndIf
   Select
      Case $msg = $Close
         Exit
      Case $msg = $MyList
         GUICtrlSetState($OpenURL, $GUI_ENABLE)
         GUICtrlSetFont($OpenURL, 9, 800)
      Case $msg = $OpenURL
         If GuiCtrlRead ($MyList) <> "" Then
            $SelectedURL = StringMid(GuiCtrlRead ($MyList), StringInStr(GuiCtrlRead ($MyList), "HTTP") - 1, 250)
            Run(@ComSpec & " /c Start " & $SelectedURL, "", @SW_HIDE)
         Else
            MsgBox(0, "No URL selected", "No URL selected!")
         EndIf
   EndSelect
Wend

Share this post


Link to post
Share on other sites

Here's a very simple (non-GUI) script that newbies might find useful as an initial introduction to AutoIt 3.

Illustrates:

  • Text file processing, including output to a LOG file.
  • Commandline processing.
  • A trick for testing before compile-and-deploy.
  • Elementary usage of a UDF.
  • Hungarian notation and proper indentation.
  • How to get around without "goto" :idiot:
  • Various methods of AU3 script deployment.
HTH :D ...
; ---------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:    English
; Author:        Trids - PM on forums at http://www.hiddensoft.com 
;
;   SCRIPT FUNCTION:
;   =================
;   an applet to convert a particular string to another in a file
;   which is dragged onto the EXE or that is passed by commandline
;
;   FEATURES
;   =================
;   + Can handle huge files (based on a request from a DBA 
;    to edit her test-scripts of around 200Mb).
;   + Prompts the user for ..
;      o Search String.
;      o Replace String 
;        (defaults with Search String for easy modification).
;      o Output file name 
;        (defaults to Input filename with ".DAT" appendix).
;
;   REQUIREMENTS
;   =================
;   + Commandline parameters
;      o Reference to an input file which has strings to replace.
;   + There may be scope in the future to make adjustments to allow
;    the utility to be run in a scheduled manner <-- in which case,
;    we would replace the current user-prompts with further
;    commandline parameters.
;
;   RESULTS
;   =================
;   - Output file with edits applied.
;   - Errors and other events are reported to a *.LOG file 
;    based on the same name and path as the script.
;
;   DEPLOYMENT
;   =================
;   - Since the applet expects to receive an input file reference from 
;    the commandline, there are several ways to launch the utility.
;      o Drag-and-Drop: just drag the input file onto the icon 
;        of the compiled EXE, or onto a shortcut to the EXE.
;      o SendTo: create a shortcut to the EXE, and place this shortcut in 
;        the "SendTo" folder. This will allow the user to rightclick on 
;        an input file and follow the "Send To" popup menu item to pass 
;        the file to the EXE.
;   
; ----------------------------------------------------------------------------

;Determine logfile name based on script's name
Global $gsFileLOG = StringTrimRight(@ScriptFullPath,3) & "LOG"

    _WriteLog(@LF & @SCRIPTNAME & " .. starting")
    
; ----------------------------------------------------------------------------
; Confirm that a commandline reference to a valid input file was passed
; ----------------------------------------------------------------------------
    
    $sMsg = ""
    If @COMPILED Then
       ;PROD --> Check for commandline parameter and validate
       ;PROD --> Check for commandline parameter and validate
       ;PROD --> Check for commandline parameter and validate
        If $CmdLine[0] = 0 Then
            $sMsg = "*** ERROR *** No commandline reference was provided, to a TXT file to reformat."
            $sFile_IN = ""
        Else
            $sFile_IN = $CmdLine[1]
        Endif
        If FileExists($sFile_IN) Then
           ;cool
        Else
            $sMsg = "*** ERROR *** The input file to reformat does not exist: """ & $sFile_IN & """"
        Endif
    Else
       ;TEST --> provide default for testing
       ;TEST --> provide default for testing
       ;TEST --> provide default for testing
        $sFile_IN = "P:\list.txt"
        $sFile_IN = "P:\bigfile.out"
        $sFile_IN = "P:\readme.txt"
        MsgBox(4096,"Debug mode", "File to reformat = """ & $sFile_IN & """")
    Endif    

; ----------------------------------------------------------------------------
; Reformat and write
; ----------------------------------------------------------------------------
    While 1 ;<-- dummy loop to avoid goto;o)
       ;check for error in dragged filename
        If $sMsg <> "" Then 
            _WriteLog($sMsg)
            ExitLoop
        Endif
        
       ;get and check the search string
        $sStr_Find = InputBox(@ScriptName, $sFile_IN & @LF & @LF & ".. FIND this:", "")
        If $sStr_Find = "" Then
            _WriteLog("*** ERROR *** Search string must not be empty.")
            ExitLoop
        Else
            _WriteLog("FIND string = """ & $sStr_Find & """")
        Endif
            
       ;get and check the replacement string
        $sStr_Replace = InputBox(@ScriptName, $sFile_IN & @LF & @LF & ".. REPLACE with:", $sStr_Find)
        If $sStr_Replace = "" Then
            _WriteLog("*** ERROR *** Replacement string must not be empty.")
            ExitLoop
        Else
            _WriteLog("REPLACE string = """ & $sStr_Replace & """")
        Endif
        
       ;get and check the output file name
        $sFile_OUT = $sFile_IN & ".dat"
        $sFile_OUT = InputBox(@ScriptName, "Output filename", $sFile_OUT)
        If $sFile_OUT = "" Then
            _WriteLog("*** ERROR *** Output filename must be specified.")
            ExitLoop
        Else
            _WriteLog("Output file = """ & $sFile_OUT & """")
        Endif
        
       ;apply the edits line by line - faster than manipulating a single string!
        $nFile_IN = FileOpen($sFile_IN,0)
        $nFile_OUT = FileOpen($sFile_OUT,2)
        If $nFile_IN = -1 Or $nFile_OUT = -1 Then 
            _WriteLog("*** ERROR **** problem opening files: (IN/OUT) = (" & $nFile_IN & "/" & $nFile_OUT & ")") 
        Else
           ;process the file
            $nHits = 0
            While 1
                $sData = FileReadLine($nFile_IN)
                If @ERROR = -1 Then ExitLoop
                $sX = StringReplace($sData, $sStr_Find, $sStr_Replace,0,0)
                If @EXTENDED <> 0 Then $nHits = $nHits + 1
                FileWriteLine($nFile_OUT, $sX)
            Wend
            FileClose($nFile_OUT)
            FileClose($nFile_IN)        

            _WriteLog("File created: """ & $sFile_OUT & """")
            _WriteLog("Lines affected: " & $nHits )
            If $nHits Then
               ;nothing to mention
            Else
                MsgBox (4096 + 48, @ScriptName, "No replacements were made!")
                _WriteLog("+++ WARNING +++ No replacements were made!")
            Endif
        Endif
        
       ;Do this all once only
        ExitLoop
    Wend

    _WriteLog(@SCRIPTNAME & " .. ending" & @LF & @LF)


Func _WriteLog($psText)
    FileWriteLine($gsFileLOG , @YEAR & "-" & @MON & "-" & @MDAY & " (" & @HOUR & ":" & @MIN & ":" & @SEC & "): " & $psText)
EndFunc

Share this post


Link to post
Share on other sites

My script compares the file http://www.autoitscript.com/fileman/users/public/Westi/update.ini with an entry in the registry

"HKEY_CURRENT_USER\Software\Check Update\Version"
If net version is greater or the entry does not exist, it downloads the file with a progressbar.

; -------------------------------------------------------------------------
;
; AutoIt Version:    3.0.103
; Platform:          WinXP-SP2
; Author:            Westi
; Script Function:   download, read and compare a ini file with a registry key 
;                    download new version with progressbar
; 3.0.103 Functions: InetGet, InetGetSize, @InetGetActive, @InetGetBytesRead, 
;                    GuiCreate, GUISetState, GUICtrlSetData, GUIGetMsg,
;                    GUICtrlCreateProgress, GUICtrlCreateLabel,
;                    GUICtrlCreateButton                                 
; Scriptname:        check_update.au3
; Version:           1.0 (23.Jan.2005)
;
; -------------------------------------------------------------------------
; Script Start
; -------------------------------------------------------------------------

;Opt("TrayIconHide", 1)
Opt("MustDeclareVars", 1)
Dim $script, $txt, $DLinifile, $regVersion, $DLini, $NewVer
Dim $reg, $updVer, $progBar, $size, $abortBtn, $DLbytes, $DLloc

$script = "Check Update"
If WinExists($script) Then Exit; It's already running
AutoItWinSetTitle($script)

$DLinifile = @ScriptDir & "\update.ini"
$regVersion = "HKEY_CURRENT_USER\Software\Check Update"
$DLloc = "http://www.autoitscript.com/fileman/users/public/Westi/"

;Delete old file
FileDelete($DLinifile)

; Load a file called 'update.ini' from $DLloc
Splash("Establish connection " & @LF & "Please wait...")
$DLini = InetGet ( $DLloc & "update.ini", $DLinifile )

;call function at the end 
Idle()

Sleep (100)
SplashOff( )

;If download fail, send message and exit
 If $DLini = 0 then
  Splash("Connection failed" & @LF & "Aborting...")
  Exit
 EndIf
;After download, open the ini file and read section[version]
;The update.ini contains one section and one value:
;_________
;[Version]
;ver=0001
;_________

If $DLini = 1 then
        Sleep (200)
        $NewVer = IniRead($DLinifile, "Version", "ver", "0")
        
;Read the installed Version from the registry
        $reg = RegRead($regVersion, "Version")
        Sleep (200)
;If $NewVer is the same as in $regVersion do nothing
;else initiate a download
                If $NewVer - $reg <= "0" then
                 Splash("No new Version available" & @LF & "Aborting...")
                 Exit
                Else
                
;Create a GUI
;with a progressbar and an 'Abort' button
                  GuiCreate($script, 300, 100)
                  $progBar =  GUICtrlCreateProgress ( 20, 40, 210, 20 )
                  $abortBtn = GUICtrlCreateButton ("Abort", 20, 70, 50, 25)
                  
;Get the size of the file to download
                  $size = InetGetSize ( $DLloc & "newver.zip" )
                    Sleep (100)
                    GUISetState ()
                    Sleep (100)
                    
;While downloading the new file
;create a label with the downloaded bytes and check the state of the 'abort' button
                    $updVer = InetGet ($DLloc & "newver.zip", @ScriptDir & "\newver.zip", 1, 1)
                    While @InetGetActive = 1

;Format the output
                    $DLbytes = StringFormat ("%.0f", 100 * @InetGetBytesRead / $size)
                    GUICtrlCreateLabel ( "Already downloaded: " & @InetGetBytesRead /1024 & "kBytes, accordingly " &  $DLbytes & "%." , 10, 10, 290, 20)

;Update the progressbar
                    GUICtrlSetData ($progBar, $DLbytes )
                      If GUIGetMsg() = $abortBtn then

;Abort the download
                       InetGet("abort")
                       Splash("Download was cancelled!" & @LF & "Aborting...")
                       Exit
                      EndIf
                    Idle()
                    Sleep (50)
                    Wend
                     Sleep (100)
                     
;Check the state after the download
;write the new version to registry
                    If $updVer = 0 then
                      Splash("Unable to download the new version!" & @LF & "Aborting...")
                      Exit
                    Else
                     Splash("New version successfully downloaded to " & @ScriptDir)
                     RegWrite ( $regVersion, "Version", "REG_SZ", $NewVer ) 
                     Sleep (100)

;Open the directory with the downloaded file
                     Run("explorer.exe " & @ScriptDir)
                    EndIf
                EndIf
EndIf
FileDelete($DLinifile)

Func Splash($txt)
SplashTextOn($script, $txt,200 ,40 ,-1 ,-1, 2,"", "10", "500")
Sleep(2000)
SplashOff( )
EndFunc

Func Idle()
; We have a multitasking environment;-)
; Give other applications cputime
; Equal function in VB is: 'DoEvents()'
RunWait("Rundll32.exe advapi32.dll,ProcessIdleTasks", @SystemDir, @SW_HIDE)
EndFunc
; -------------------------------------------------------------------------
; Script End
; -------------------------------------------------------------------------
This script uses a dummy file (~3MB). Don't use it so often, 'cause bandwith. Edited by Westi

Share this post


Link to post
Share on other sites

The following script is designed to show off the drag/drop functionality of Autoit 3.1  It was tested and compiled with a post 3.1.0 release, which incorporated multiple file drag/drop support. *Should* work under 3.1.0, though only one file at a time will be able to be dropped.

;===============================================================================

; Script Name:            DragDrop.Au3
; Description:            Demonstrate Handling a FileDrop Operation in Autoit 3.x
; Parameter(s):           None
; Requirement(s):         Not tested under 3.1.0 or earlier
; Return Value(s):        None
; Author(s):              FlyingBoz
; Date:                   20 Feb 2005
;===============================================================================



#include <GuiConstants.au3>

; GUI
;Note GUI Created with the Extended Windows Style ACCEPTFILES
GUICreate("Drag/Drop Demo", 220, 220, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; INPUT
;string for default status of InputBox
Global Const $txtInput = "Input Box Accepts Files"
;Create handle for Input Box.
Global $hInput = GUICtrlCreateInput($txtInput, 10, 10, 200, 200);Specify that the control can respond to ACCEPTFILES messages
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUISetState()
;Initialize Message Status
Local $msg = ""
; GUI MESSAGE LOOP
While $msg <> $GUI_EVENT_CLOSE
   $msg = GUIGetMsg()
  ;UDF to Monitor Controls that Accept Drag / Drop
  ;This is necessary becuase the drop operation does NOT send a message to the control,
  ;It simply dumps the CRLF separated list of files in the control, appending them to what went before.
   _MonitorFiles()
   
WEnd
Exit $msg

;===============================================================================
;
; Function Name:      _MonitorFiles
; Description:        Demonstrate Looping to Monitor the change of a drag/drop file operation
; Parameter(s):       None
; Requirement(s):     Autoit3.1.0
; Return Value(s):    None
; Author(s):          FlyingBoz
; Date:               20 Feb 2005

Func _MonitorFiles()
  ;FlyingBoz - monitor contents of $hinput control,
  ;display and reset when triggered.
   Local $text = GUICtrlRead($hInput)
   If $text <> $txtInput Then;Something has changed
    ;strip the default text
      $text = StringReplace($text, $txtInput, "")
    ;display what's left.
      MsgBox(0, "Change In Input Box!", $text, 0)
    ;NOTE: Obviously, more sophisticated handling 
   ;should occur here - You will see when Files are 
  ;dropped, this @CRLF separated list
    ;can be parsed, tested with If FileExists(), etc.
    
      GUICtrlSetData($hInput, $txtInput)
   EndIf
EndFunc  ;==> _MonitorFiles
;===============================================================================

Edited for cosmetics.

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

; AutoIt Version: 3.0
; Language: English
; Platform: Win98 2nd edition, Win XP and May work on other windows
; In order to work under Windows NT 4.0, requires the file
; PSAPI.DLL (included in the AutoIt installation directory).
; Author: Quick_sliver007
; Script Name: Process Blocker
; version: 1.3
; Script Function: To Block unwanted processes like spyware and adware
; fixed : Made block process list view clear before loading file,
; resized gui, cleaned up script with functions, added fade function,
; added shortcut keys and added annotation
#include <GuiConstants.au3>
#include <Array.au3>
#include <file.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; START OF GUI CREATION
$GUI = GUICreate("Process Blocker", 565, 419, (@DesktopWidth - 565) / 2, (@DesktopHeight - 409) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Process_List_View = GUICtrlCreateListView("Processes", 1, 30, 220, 370)
$Block_List_view = GUICtrlCreateListView("Block", 344, 30, 220, 370)
$Label_Process = GUICtrlCreateLabel("Process List", 10, 10, 220, 20)
$Label_Block = GUICtrlCreateLabel("Block List", 340, 10, 220, 20)
$Label_Add = GUICtrlCreateLabel("Add To Block List", 240, 30, 90, 20)
$Button_Add = GUICtrlCreateButton("&Add", 240, 50, 90, 30)
$Button_Delete = GUICtrlCreateButton("&Delete", 240, 130, 90, 30)
$Label_Delete = GUICtrlCreateLabel("Delete From List", 240, 110, 90, 20)
$Button_Reset = GUICtrlCreateButton("&Reset", 240, 270, 90, 50)
$Button_Block = GUICtrlCreateButton("&Block", 240, 190, 90, 50)
$Button_Exit = GUICtrlCreateButton("&Exit", 240, 350, 90, 50)
$Menu = GUICtrlCreateMenu("&File")
$Save = GUICtrlCreateMenuItem("&Save", $Menu)
$Load = GUICtrlCreateMenuItem("&Load", $Menu)
$Button_Donate = GUICtrlCreateButton("&Donate", 240, 10, 90, 20)
GUISetState(); END OF GUI CREATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; IN THE HELP FILE IT SENDS ProcessList() TO A MESSAGE BOX.....
; I HAD THE IDEAL TO SEND IT TO A LIST VIEW
Func _processlist()
    Dim $LVM_DELETEITEM = 0x1008
    $Process = ProcessList()
    For $i = 1 To $Process[0][0]
        $items = GUICtrlCreateListViewItem($Process[$i][0], $Process_List_View)
    Next
EndFunc  ;==>_processlist
_processlist()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Global $break = 0
; USE THIS FUNCTION TO EXIT THE RUN LOOP
; THANKS GOES TO erifash
Func _break()
    $break = 1
EndFunc  ;==>_break
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; USE THIS FUNCTION TO OPEN AN URL ON THE DEFAULT BROWSER
; THANKS TO Ejoc AND SlimShady FOR THIS FUNCTIONS
Func _GoToWebPage($URL)
    Run(@comspec & ' /c START "" "' & $URL & '"', @SystemDir, @SW_HIDE)
EndFunc  ;==>_GoToWebPage
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;THANKS TO bshoenhair FOR POINTING TO "http://www.autoitscript.com/forum/index.php?showtopic=7026&hl="
;USE THIS FUNCTION TO MOVE SELECTED ITEM BETWEEN LIST VIEWS
Func _Move_Selected_Item_To_Another_List_View($Source_List_View, $destination_List_view)
    Dim $LVM_DELETEITEM, $a, $ItemCount, $Source_Title
;COPY SELCTED ITEM FROM SOURCE LIST VIEW AND PASTE IT TO THE DESTINATION LIST VIEW
    GUICtrlCreateListViewItem(GUICtrlRead(GUICtrlRead($Source_List_View)), $destination_List_view)
; THIS NUMBER IS USED TO DELETE AN ITEM FROM A LIST VIEW, SOME TYPE OF...
; MICROSOFT STANDARD CONTROL NUMBER, I JUST KNOW IT WORKS
    $LVM_DELETEITEM = 0x1008
    $ItemCount = ControlListView("", "", $Source_List_View, "GetItemCount")
    For $a = 0 To $ItemCount - 1
        If ControlListView("", "", $Source_List_View, "IsSelected", $a) Then
        ;DELETES THE SELECTED ITEM FROM THE SOURCE LIST VIEW
            GUICtrlSendMsg($Source_List_View, $LVM_DELETEITEM, $a, 0)
        EndIf
    Next
EndFunc  ;==>_Move_Selected_Item_To_Another_List_View
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; USE THIS FUNCTION TO CLEAR ALL ITEMS IN A LIST VIEW
Func _clearlistview($List_View)
    #cs
    Do
        Dim $LVM_DELETEITEM, $a, $ItemCount
        $LVM_DELETEITEM = 0x1008
        $ItemCount = ControlListView("", "", $List_View, "GetItemCount")
        For $a = 0 To $ItemCount - 1
            GUICtrlSendMsg($List_View, $LVM_DELETEITEM, $a, 0)
        Next
;DO UNTIL ALL ITEMS ARE CLEARED 
    Until $ItemCount = 0
    #ce
; I FOUND A BETTER WAY, THANKS TO Gary Frost AUTHOR OF CFCCodeWizard
; AS YOU CAN SEE THERE IS MORE THEN ONE WAY AND HIS WAY IS THE CORRECT.
    Local $LVM_DELETEALLITEMS = 0x1009
   GUICtrlSendMsg($LIST_VIEW, $LVM_DELETEALLITEMS, 0, 0)
EndFunc  ;==>_clearlistview
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; THANKS TO Lazycat FOR THE Fade FUNCTION
; AUTHOR OF Quick Notepad v0.5
; CAUSES THE GUI TO FADE IN OR OUT
; I BELIEVE $nStart AND $nEnd ARE BACKARDS
; $nEnd = HOW TRANSPARENT THE WINDOW STARTS, RANGE 0 - 255
; $nStart = HOW TRANSPARENT THE WINDOW ENDS, RANGE 0 - 255
; $hWnd IS THE WINDOW NAME
; $nStep IS HOW FAST
Func Fade($hWnd, $nStart, $nEnd, $nStep)
    If not $nStep Then Return
    For $t = $nStart to $nEnd step $nStep * ($nEnd - $nStart)/Abs($nEnd - $nStart)
        WinSetTrans ($hWnd, "", $t)
    Next
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While 1
    Dim $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_Add
        ; ADD ITEM FROM $Process_List_View TO $Block_List_view
            _Move_Selected_Item_To_Another_List_View($Process_List_View, $Block_List_view)
        Case $msg = $Button_Delete
        ; MOVE ITEM BACK TO $Process_List_View
            _Move_Selected_Item_To_Another_List_View($Block_List_view, $Process_List_View)
        Case $msg = $Button_Block
        ; THIS WHOLE AREA IS THE CORE OF THE SCRIPT
        ; THIS AREA IS WHERE PROCESSES ARE BLOCKED
            Fade($gui, 100, 0, 10)
            GUISetState(@SW_HIDE, $GUI)
            HotKeySet("{ESC}", "_break")
            While 1
                Dim $count_items, $Get_text, $b
            ;COUNT ITEMS IN THE $Block_List_view
                $count_items = ControlListView("Process Blocker", "", $Block_List_view, "GetItemCount")
                For $b = 0 To $count_items - 1
                ; GET ALL OF THE ITEMS IN THE $Block_List_view
                    $Get_text = ControlListView("Process Blocker", "", $Block_List_view, "GetText", $b)
                ; CLOSE ALL OF THE ITEMS IN THE $Block_List_view UNTIL THE LOOP IS BROKEN
                    ProcessClose($Get_text)
                Next
            ; USED TO BREAK THE LOOP
                If $break = 1 Then
                    HotKeySet("{ESC}")
                    $break = 0
                    GUISetState(@SW_SHOW, $GUI)
                    Fade($gui, 0,250, 3)
                    ExitLoop
                EndIf
            WEnd
        Case $msg = $Button_Reset
        ; RESET ALL OF THE LIST VIEWS AND ENABLE THE BUTTONS IF THE....
        ; BUTTONS WERE DISABLED FROM LOADING THE SAVE FILE
            _clearlistview($Process_List_View)
            _clearlistview($Block_List_view)
            _processlist()
            GUICtrlSetState($Button_Add, $GUI_ENABLE)
            GUICtrlSetState($Button_Delete, $GUI_ENABLE)
        Case $msg = $Save
            Dim $count_items, $b
            If FileExists("BlockProcessesSave.txt") Then
            ;DELETE THE OLD FILE BEFORE WRITING A NEW ONE SO THAT THE LAST SAVE IS REPLACED
                FileDelete("BlockProcessesSave.txt")
                $count_items = ControlListView("Process Blocker", "", $Block_List_view, "GetItemCount")
                For $b = 0 To $count_items - 1
                    Dim $Get_text[$count_items]
                    $file = FileOpen("BlockProcessesSave.txt", 1)
                ;SET ALL ITEMS IN THE $Block_List_view TO AN ARRAY
                    $Get_text[$b] = ControlListView("Process Blocker", "", $Block_List_view, "GetText", $b)
                    Do
                    ; GIVE TIME FOR THE FILE TO BE OPENED/CREATED BEFORE WRITING FILE
                        Sleep(1000)
                    Until FileExists("BlockProcessesSave.txt")
                ;WRITE ALL ITEMS IN THE ARRAY TO THE FILE
                    FileWrite($file, $Get_text[$b] & @CRLF)
                    FileClose($file)
                Next
            ElseIf Not FileExists("BlockProcessesSave.txt") Then
                $count_items = ControlListView("Process Blocker", "", $Block_List_view, "GetItemCount")
                For $b = 0 To $count_items - 1
                    Dim $Get_text[$count_items]
                    $file = FileOpen("BlockProcessesSave.txt", 1)
                    $Get_text[$b] = ControlListView("Process Blocker", "", $Block_List_view, "GetText", $b)
                    Do
                        Sleep(1000)
                    Until FileExists("BlockProcessesSave.txt")
                    FileWrite($file, $Get_text[$b] & @CRLF)
                    FileClose($file)
                Next
            EndIf
        Case $msg = $Load
        ; CLEAR ALL ITEMS BEFORE LOADING
            _clearlistview($Block_List_view)
            _clearlistview($Process_List_View)
            Dim $aRecords
            If Not _FileReadToArray("BlockProcessesSave.txt", $aRecords) Then
                MsgBox(4096, "Error", "Make Sure You Have A Saved List")
                Exit
            EndIf
            For $x = 1 To $aRecords[0]
            ; $aRecords[$x] IS AN ARRAY THAT CONTAINS THE ITEMS FROM THE SAVE FILE
            ; SET THE $Block_List_view ITEMS TO THE ITEMS STORED IN THE ARRAY
            ; THE STRING TRIM IS TO CUT OUT THE LAST CHARACTER ,A SQUARE SHAPED CHARACTER
            ; I BELIEVE THE SQUARE IS FROM LINE BREAKS I USED IN WRITING THE SAVE FILE
                GUICtrlCreateListViewItem(StringTrimRight($aRecords[$x], 1), $Block_List_view)
            Next
        ; DISABLE BUTTONS TO AVOID ERRORS
            GUICtrlSetState($Button_Add, $GUI_DISABLE)
            GUICtrlSetState($Button_Delete, $GUI_DISABLE)
            GUICtrlCreateListViewItem("Click reset to reload list.", $Process_List_View)
        Case $msg = $Button_Donate
        ; EVERY DOLLAR COUNTS AND
        ; EVERY PENNY COUNTS TOO, LOL
            _GoToWebPage("https://www.paypal.com/xclick/business=quick_sliver007%40yahoo%2ecom&no_shipping=0&no_note=1&tax=0&currency_code=USD")
        Case $msg = $Button_Exit
            Exit
    EndSelect
WEnd
#cs
    I HOPE I DIDN'T GO OVER KILL WITH THE ANNOTATION. I ALL WAYS WANTED WELL ANNOTATED SCRIPTS
    TO LEARN FROM WHEN I HAD JUST STARTED TO LEARN AUTOLT 3. THE ONES I DID FIND WERE FAR AND FEW BETWEEN.
    SO I JUST WANTED TO ADD ONE TO THE PILE OF WELL ANNOTATED SCRIPTS FOR PEOPLE TO LEARN FROM. I KNOW
    I STILL HAVE A LOT MORE TO LEARN IN AUTOLT 3 BUT I WOULD LIKE TO HELP GIVE PEOPLE THAT ARE NEW
    SOMETHING MORE TO LEARN FROM. FOR NOW AM DONE WITH THIS SCRIPT. IF YOU FIND A BUG, FEEL FREE TO
    LET ME KNOW. I GIVE MANY THANKS TO ALL OF THE PEOPLE ON THE AUTOLT FORUM THAT HAVE HELPED ME LEARN
    THIS LANGUAGE.
    P.S.
    FEEL FREE TO DONATE.
#CE

Process_Blocker_v1.3.Au3


.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...