Jump to content

autorun


w00blyn
 Share

Recommended Posts

Ahoy! This took me 6 hours last night and 4 more today, brutal I know, but its my first "real" script.

All it does is start a timer when windows starts, then start shortcuts one by one with a countdown between each. I'd normally use WinWait, but my friend wants something easy to use. And I had trouble getting WinWait to work with Gigastudios. I'd like to add a gui that can scan the profiles directory then show each *.ini in a combo box so the user can choose which one to use at startup. Maybe even allow editing of each. For now its just a bunch of input boxes, quick 'n dirty.

Can I do a GetFileLongName with *.ini somehow? Return an array that's got each filename from the folder? Haven't done anything with arrays yet, maybe someone can steer me the right way.

One more quick question, does

#include <GUIConstants.au3>

scan the scriptdirectory for the file as well as the autoit install folder? Or does it add the guiconstants to the exe when it compiles, so it doesn't really have to look anywhere for it?

Heres my scripts:

autorun.au3

#include <GUIConstants.au3>
opt("GUIOnEventMode", 1)

;variables
$profile = IniRead(@ScriptDir & "\" & "autorun.ini", "Options", "Profile", "default")
$time = IniRead(@ScriptDir & "\" & $profile & ".ini", "Options", "Countdown", "15")
$launch = 0
$debug = 0


;controls
$form = GUICreate("Launch Software in:", 200, 125, -1, -1, "", $WS_EX_TOPMOST)
$progress = GUICtrlCreateProgress(10, 10, 180, 20, "")
$label = GUICtrlCreateLabel("", 10, 40, 180, 20, $SS_CENTER)


;buttons
$cancel = GUICtrlCreateButton("Cancel", 120, 60, 60, 30)
GUICtrlSetOnEvent($cancel, "Done")
$pause = GUICtrlCreateButton("Pause", 20, 60, 60, 30)
GUICtrlSetOnEvent($pause, "Pause")


;---initiate the countdown
GUISetState(@SW_SHOW)
$msg = GUIGetMsg()
While $launch = 0
    For $s = $time To 0 Step - 1
        GUICtrlSetData($label, "Launch in " & $s & "...")
        GUICtrlSetData($progress, (1 - $s / $time) * 100)
        Sleep(1000)
    Next
    Call("Launch")
WEnd

;---launch shortcut
Func Launch()
    Do
        $launch = $launch + 1
        $appcount = IniRead(@ScriptDir & "\Profiles\" & $profile & ".ini", "Options", "AppCount", "1")
        $title = IniRead(@ScriptDir & "\Profiles\" & $profile & ".ini", "App" & $launch, "Title", "default")
        $cycles = IniRead(@ScriptDir & "\Profiles\" & $profile & ".ini", "App" & $launch, "Cycles", "1")
        $sleep = IniRead(@ScriptDir & "\Profiles\" & $profile & ".ini", "App" & $launch, "Sleep", "1")
        GUICtrlSetData($label, $title)
        Sleep(1000)
        Do
            $cycles = $cycles - 1
            If FileExists(@ScriptDir & "\Shortcuts\" & $title & ".lnk") Then
                Run(@ComSpec & " /c Start Shortcuts\" & $title, "", @SW_HIDE)
            Else
                If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
                $iMsgBoxAnswer = MsgBox(48, "AutoRun", "Cannot find shortcut! Skipping...", 2)
                Select
                    Case $iMsgBoxAnswer = -1
                    Case Else
                EndSelect
            EndIf
            For $s = $sleep To 0 Step - 1
                GUICtrlSetData($label, $title & " will finish in " & $s)
                GUICtrlSetData($progress, (1 - $s / $sleep) * 100)
                Sleep(1000)
            Next
            GUICtrlSetData($label, $title & " is finished...")
            Sleep(1000)
        Until $cycles < 1
    Until $launch >= $appcount
    Call("Done")
EndFunc  ;==>Launch

;---pause
Func Pause()
    MsgBox(262192, "Software Launch", "Paused!")
EndFunc  ;==>Pause
;---exit
Func Done()
    GUICtrlSetData($label, "Done!")
    Sleep(1000)
    Exit
EndFunc  ;==>Done

configmaker.au3

#include <GUIConstants.au3>
opt("GUIOnEventMode", 1)
$ap = 0
Dim $iMsgBoxAnswer, $sInputBoxAnswer, $cd, $a
;create profile
$iMsgBoxAnswer = MsgBox(1, "AutoRun", "Would you like to create a new profile?")
Select
    Case $iMsgBoxAnswer = 1;OK
    Case $iMsgBoxAnswer = 2;Cancel
        done("OK, ")
EndSelect

;---name profile
$sInputBoxAnswer = InputBox("Profile", "Please name your profile:", "default", " M", "-1", "-1", "-1", "-1")
Select
    Case @error = 0;OK - The string returned is valid
        $profile = $sInputBoxAnswer
    Case @error = 1;The Cancel button was pushed
        done("Cancelled, ")
    Case @error = 3;The InputBox failed to open
        done("Something went wrong, ")
EndSelect

;---find countdown
$sInputBoxAnswer = InputBox("AutoRun", "How many seconds should the initial countdown be?", "10", " M", "-1", "-1", "-1", "-1")
Select
    Case @error = 0;OK - The string returned is valid
        _countdown($sInputBoxAnswer)
    Case @error = 1;The Cancel button was pushed
        done("Cancelled, ")
    Case @error = 3;The InputBox failed to open
        done("Something went wrong, ")
EndSelect

;---find appcount
$sInputBoxAnswer = InputBox("AutoRun", "How many *different* programs would you like to run?", "1", " M", "-1", "-1", "-1", "-1")
Select
    Case @error = 0;OK - The string returned is valid
        $appcount = ($sInputBoxAnswer)
        _appcount($sInputBoxAnswer)
    Case @error = 1;The Cancel button was pushed
        done("Cancelled, ")
    Case @error = 3;The InputBox failed to open
        done("Something went wrong, ")
EndSelect


;---start adding info
While $ap < $appcount
    $ap = $ap + 1
    
;---find title
    $sInputBoxAnswer = InputBox("AutoRun", "Enter the title for shortcut number " & $ap, "default", " M", "-1", "-1", "-1", "-1")
    Select
        Case @error = 0;OK - The string returned is valid
            _title($iMsgBoxAnswer)
        Case @error = 1;The Cancel button was pushed
            done("Cancelled, ")
        Case @error = 3;The InputBox failed to open
            done("Something went wrong, ")
    EndSelect
    
;---find cycles
    $sInputBoxAnswer = InputBox("AutoRun", "How many times would you like that program to run?", "1", " M", "-1", "-1", "-1", "-1")
    Select
        Case @error = 0;OK - The string returned is valid
            _cycles($iMsgBoxAnswer)
        Case @error = 1;The Cancel button was pushed
            done("Cancelled, ")
        Case @error = 3;The InputBox failed to open
            done("Something went wrong, ")
    EndSelect
    
;---find sleep
    $sInputBoxAnswer = InputBox("AutoRun", "How many seconds should we wait for this program to finish loading?", "1", " M", "-1", "-1", "-1", "-1")
    Select
        Case @error = 0;OK - The string returned is valid
            _sleep($iMsgBoxAnswer)
        Case @error = 1;The Cancel button was pushed
            done("Cancelled, ")
        Case @error = 3;The InputBox failed to open
            done("Something went wrong, ")
    EndSelect
WEnd
done("Finished, ")

;---set countdown
Func _countdown($cd)
    IniWrite(@ScriptDir & "\Profiles\" & $profile & ".ini", "Options", "Countdown", $cd)
EndFunc  ;==>_countdown

;---set appcount
Func _appcount($a)
    IniWrite(@ScriptDir & "\Profiles\" & $profile & ".ini", "Options", "AppCount", $a)
EndFunc  ;==>_appcount

;---set title
Func _title($t)
    IniWrite(@ScriptDir & "\Profiles\" & $profile & ".ini", "App" & $ap, "Title", $t)
EndFunc  ;==>_title

;---set cycles
Func _cycles($c)
    IniWrite(@ScriptDir & "\Profiles\" & $profile & ".ini", "App" & $ap, "Cycles", $c)
EndFunc  ;==>_cycles

;---set sleep
Func _sleep($s)
    IniWrite(@ScriptDir & "\Profiles\" & $profile & ".ini", "App" & $ap, "Sleep", $s)
EndFunc  ;==>_sleep

;---quit
Func done($d)
    $iMsgBoxAnswer = MsgBox(0, "AutoRun", $d & "exiting...", 1)
    Select
        Case $iMsgBoxAnswer = -1;Timeout
            Exit
        Case Else              ;OK
            Exit
    EndSelect
EndFunc  ;==>done

Suggestions are very much appreciated :lmao:

AutoRun.rar

Link to comment
Share on other sites

Can I do a GetFileLongName with *.ini somehow? Return an array that's got each filename from the folder? Haven't done anything with arrays yet, maybe someone can steer me the right way.

One more quick question, does

i'm not sure what you mean about the INI

but maybe (needs beta i think)

_FileListToArray 
--------------------------------------------------------------------------------

lists files and\or folders in a specified path (Similar to using Dir with the /B Switch)


#include <File.au3>
_FileListToArray($sPath [, $sFilter [, $iFlag]])
Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...