Jump to content

Help stopping script


Recommended Posts

Well I can usually find what I am looking for and adjust it to suit my needs but I think I am stumped.

Here is my script and what I would like it to do is stop when I hit the stop button. However once I hit start all other buttons do not work at all. I do not wish to exit the script just stop it allowing me to start from the beginning if I hit start again.

My code is probably considered a mess to a lot which is why I am also taking any constructive critisism.... please be nice muttley

Main Script

CODE
HotKeySet("{F4}", "Terminate")

#include <IE.au3>

#include <GUIConstantsEx.au3>

#include <Constants.au3>

#include <GUIConstantsEx.au3>

#include <file.au3>

#NoTrayIcon

$key = IniRead("AutoViewer.ini", "Key", "key", "Registry Key Not Found")

$inisize = _FileCountLines("AutoViewer.ini") +1

$ActProxy = RegRead($key, "ProxyServer")

RegWrite($key, "ProxyEnabled", "REG_DWORD", 0) ;Upon startup set these values

RegWrite($key, "ProxyEnable", "REG_DWORD", 0)

GUICreate("AutoViewer", 430, 120)

GUICtrlCreateLabel("Enter your URLs here", 30, 2)

$url1 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url1", "No Url Entered"), 10, 15, 300, 20)

$url2 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url2", "No Url Entered"), 10, 35, 300, 20)

$url3 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url3", "No Url Entered"), 10, 55, 300, 20)

$url4 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url4", "No Url Entered"), 10, 75, 300, 20)

$save = GUICtrlCreateButton("Save URLs", 15, 100, 60, 20)

$start = GUICtrlCreateButton("Start", 190, 100, 60, 20)

$stop = GUICtrlCreateButton("Stop", 250, 100, 60, 20)

GUICtrlSetState(-1, 1)

$about = GUICtrlCreateButton("About", 310, 100, 60, 20)

$exit = GUICtrlCreateButton("Exit", 370, 100, 60, 20)

$proxy = GUICtrlCreateCheckbox("Use Proxy?", 320, 15, 80, 20)

$curproxy = GUICtrlCreateButton("Current Proxy", 320, 35, 90, 20)

GUICtrlSetState(-1, $GUI_DISABLE)

$numproxy = GUICtrlCreateButton("Number of Proxies", 320, 55, 98, 20)

GUICtrlSetState(-1, $GUI_DISABLE)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $proxy And BitAND(GUICtrlRead($proxy), $GUI_CHECKED) = $GUI_CHECKED

RegWrite($key, "ProxyEnabled", "REG_DWORD", 1)

RegWrite($key, "ProxyEnable", "REG_DWORD", 1)

GUICtrlSetState($curproxy, $GUI_ENABLE)

GUICtrlSetState($numproxy, $GUI_ENABLE)

Case $msg = $proxy And BitAND(GUICtrlRead($proxy), $GUI_UNCHECKED) = $GUI_UNCHECKED

RegWrite($key, "ProxyEnabled", "REG_DWORD", 0)

RegWrite($key, "ProxyEnable", "REG_DWORD", 0) ; No Proxy

GUICtrlSetState($curproxy, $GUI_DISABLE)

GUICtrlSetState($numproxy, $GUI_DISABLE)

Case $msg = $save

IniWrite("AutoViewer.ini", "Url", "url1", GUICtrlRead($url1))

IniWrite("AutoViewer.ini", "Url", "url2", GUICtrlRead($url2))

IniWrite("AutoViewer.ini", "Url", "url3", GUICtrlRead($url3))

IniWrite("AutoViewer.ini", "Url", "url4", GUICtrlRead($url4))

Case $msg = $curproxy

Msgbox(0,"Number of Proxies","You have " & $inisize -11 & " proxies in your list")

Case $msg = $numproxy

Msgbox(0,"Current Proxy","The proxy being used is" & @LF & $ActProxy)

Case $msg = $about

Msgbox(0,"About","AutoViewer" & @LF & "Version 1.4" & @LF & "Coded by: DvHrld" & @LF & "http://autoviewer.co.nr")

Case $msg = $start

Do

For $count = 11 to $inisize

$line = FileReadLine("AutoViewer.ini", $count)

RegWrite($key, "ProxyServer", "REG_SZ", $line)

Sleep(1000)

$oIE = _IECreate($url1, 0, 0, 0, 0)

Sleep(8000)

__IENavigate($oIE, $url2, 0, 4096) ; open in a new background tab

Sleep(5000)

__IENavigate($oIE, $url3, 0, 4096) ; open in a new background tab

Sleep(5000)

__IENavigate($oIE, $url4, 0, 4096) ; open in a new background tab

Sleep(180000)

ProcessClose("iexplore.exe")

Sleep(2000)

Next

Until Case $msg = $stop

Case $msg = $stop

ProcessClose("iexplore.exe")

ExitLoop

Sleep(800)

Case $msg = $exit

ProcessClose("iexplore.exe")

Sleep(800)

Exit 0

EndSelect

WEnd

Func Terminate()

ProcessClose("iexplore.exe")

Sleep(800)

Exit 0

EndFunc

Ini File

CODE
AutoViewer first public AutoIt script
Link to comment
Share on other sites

Thansk for your help Achilles, I have come up with this rewrite using GuiOnEventMode but with some new problems the while loop starts automatically, which I would like it to start only when the start button is pressed. Also once it is stopped I would like to be able to press the the start button to start it again.

I have commented out some code because it creates errors but it shows kinda what I am looking for.

CODE
HotKeySet("{F4}", "Terminate")

#include <IE.au3>

#include <GUIConstantsEx.au3>

#include <Constants.au3>

#include <GUIConstantsEx.au3>

#include <file.au3>

#NoTrayIcon

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$key = IniRead("AutoViewer.ini", "Key", "key", "Registry Key Not Found")

$inisize = _FileCountLines("AutoViewer.ini") +1

$ActProxy = RegRead($key, "ProxyServer")

RegWrite($key, "ProxyEnabled", "REG_DWORD", 0) ;Upon startup set these values

RegWrite($key, "ProxyEnable", "REG_DWORD", 0)

GUICreate("AutoViewer", 430, 120)

GUICtrlCreateLabel("Enter your URLs here", 30, 2)

$url1 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url1", "No Url Entered"), 10, 15, 300, 20)

$url2 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url2", "No Url Entered"), 10, 35, 300, 20)

$url3 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url3", "No Url Entered"), 10, 55, 300, 20)

$url4 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url4", "No Url Entered"), 10, 75, 300, 20)

$save = GUICtrlCreateButton("Save URLs", 15, 100, 60, 20)

GUICtrlSetOnEvent($save, "save")

$start = GUICtrlCreateButton("Start", 190, 100, 60, 20)

;GUICtrlSetOnEvent($start, "start")

$stop = GUICtrlCreateButton("Stop", 250, 100, 60, 20)

GUICtrlSetOnEvent($stop, "stop")

$about = GUICtrlCreateButton("About", 310, 100, 60, 20)

GUICtrlSetOnEvent($about, "about")

$exit = GUICtrlCreateButton("Exit", 370, 100, 60, 20)

GUICtrlSetOnEvent($exit, "Terminate")

$proxy = GUICtrlCreateCheckbox("Use Proxy?", 320, 15, 80, 20)

GUICtrlSetOnEvent($proxy, "proxy")

$curproxy = GUICtrlCreateButton("Current Proxy", 320, 35, 90, 20)

GUICtrlSetState(-1, $GUI_DISABLE)

GUICtrlSetOnEvent($curproxy, "curproxy")

$numproxy = GUICtrlCreateButton("Number of Proxies", 320, 55, 98, 20)

GUICtrlSetState(-1, $GUI_DISABLE)

GUICtrlSetOnEvent($numproxy, "numproxy")

GUISetState(@SW_SHOW)

While 1

For $count = 11 to $inisize

$line = FileReadLine("AutoViewer.ini", $count)

RegWrite($key, "ProxyServer", "REG_SZ", $line)

Sleep(1000)

$oIE = _IECreate($url1, 0, 0, 0, 0)

Sleep(8000)

__IENavigate($oIE, $url2, 0, 4096) ; open in a new background tab

Sleep(5000)

__IENavigate($oIE, $url3, 0, 4096) ; open in a new background tab

Sleep(5000)

__IENavigate($oIE, $url4, 0, 4096) ; open in a new background tab

Sleep(180000)

ProcessClose("iexplore.exe")

Sleep(2000)

Next

WEnd

Func proxy()

If $proxy And BitAND(GUICtrlRead($proxy), $GUI_CHECKED) = $GUI_CHECKED Then

RegWrite($key, "ProxyEnabled", "REG_DWORD", 1)

RegWrite($key, "ProxyEnable", "REG_DWORD", 1)

GUICtrlSetState($curproxy, $GUI_ENABLE)

GUICtrlSetState($numproxy, $GUI_ENABLE)

Else

If $proxy And BitAND(GUICtrlRead($proxy), $GUI_UNCHECKED) = $GUI_UNCHECKED Then

RegWrite($key, "ProxyEnabled", "REG_DWORD", 0)

RegWrite($key, "ProxyEnable", "REG_DWORD", 0) ; No Proxy

GUICtrlSetState($curproxy, $GUI_DISABLE)

GUICtrlSetState($numproxy, $GUI_DISABLE)

EndIf

EndIf

EndFunc

Func save()

IniWrite("AutoViewer.ini", "Url", "url1", GUICtrlRead($url1))

IniWrite("AutoViewer.ini", "Url", "url2", GUICtrlRead($url2))

IniWrite("AutoViewer.ini", "Url", "url3", GUICtrlRead($url3))

IniWrite("AutoViewer.ini", "Url", "url4", GUICtrlRead($url4))

EndFunc

Func numproxy()

Msgbox(0,"Number of Proxies","You have " & $inisize -11 & " proxies in your list")

EndFunc

Func curproxy()

Msgbox(0,"Current Proxy","The proxy being used is" & @LF & $ActProxy)

EndFunc

Func about()

Msgbox(0,"About","AutoViewer" & @LF & "Version 1.4" & @LF & "Coded by: DvHrld" & @LF & "http://autoviewer.co.nr")

EndFunc

;Func start()

;ContinueLoop

;EndFunc

Func stop()

ProcessClose("iexplore.exe")

Sleep(800)

EndFunc

Func Terminate()

ProcessClose("iexplore.exe")

Sleep(800)

Exit 0

EndFunc

AutoViewer first public AutoIt script
Link to comment
Share on other sites

I'm not exactly sure how to test it but I think I might of made it more functional, I added a GuiOnEvent($GUI_EVENT_ClOSE, 'Terminate') which means if you press the little X it exits using your Terminate function. I moved the Loop part to the start function, and in the loop I added some GuiCtrlReads which you need to actually gather the data from the input controls.

HotKeySet("{F4}", "Terminate")
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <file.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1); Change to OnEvent mode

$key = IniRead("AutoViewer.ini", "Key", "key", "Registry Key Not Found")
$inisize = _FileCountLines("AutoViewer.ini") + 1
$ActProxy = RegRead($key, "ProxyServer")

RegWrite($key, "ProxyEnabled", "REG_DWORD", 0);Upon startup set these values
RegWrite($key, "ProxyEnable", "REG_DWORD", 0)

GUICreate("AutoViewer", 430, 120)
    GuiSetOnEvent($GUI_EVENT_CLOSE, 'Terminate')
GUICtrlCreateLabel("Enter your URLs here", 30, 2)
$url1 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url1", "No Url Entered"), 10, 15, 300, 20)
$url2 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url2", "No Url Entered"), 10, 35, 300, 20)
$url3 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url3", "No Url Entered"), 10, 55, 300, 20)
$url4 = GUICtrlCreateInput(IniRead("AutoViewer.ini", "Url", "url4", "No Url Entered"), 10, 75, 300, 20)
$save = GUICtrlCreateButton("Save URLs", 15, 100, 60, 20)
GUICtrlSetOnEvent($save, "save")
$start = GUICtrlCreateButton("Start", 190, 100, 60, 20)
GUICtrlSetOnEvent($start, "start")
$stop = GUICtrlCreateButton("Stop", 250, 100, 60, 20)
GUICtrlSetOnEvent($stop, "stop")
$about = GUICtrlCreateButton("About", 310, 100, 60, 20)
GUICtrlSetOnEvent($about, "about")
$exit = GUICtrlCreateButton("Exit", 370, 100, 60, 20)
GUICtrlSetOnEvent($exit, "Terminate")

$proxy = GUICtrlCreateCheckbox("Use Proxy?", 320, 15, 80, 20)
GUICtrlSetOnEvent($proxy, "proxy")
$curproxy = GUICtrlCreateButton("Current Proxy", 320, 35, 90, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetOnEvent($curproxy, "curproxy")
$numproxy = GUICtrlCreateButton("Number of Proxies", 320, 55, 98, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetOnEvent($numproxy, "numproxy")

GUISetState(@SW_SHOW)

While 1
    Sleep(200)
WEnd


Func proxy()
    If $proxy And BitAND(GUICtrlRead($proxy), $GUI_CHECKED) = $GUI_CHECKED Then
        RegWrite($key, "ProxyEnabled", "REG_DWORD", 1)
        RegWrite($key, "ProxyEnable", "REG_DWORD", 1)
        GUICtrlSetState($curproxy, $GUI_ENABLE)
        GUICtrlSetState($numproxy, $GUI_ENABLE)
    Else
        If $proxy And BitAND(GUICtrlRead($proxy), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
            RegWrite($key, "ProxyEnabled", "REG_DWORD", 0)
            RegWrite($key, "ProxyEnable", "REG_DWORD", 0); No Proxy
            GUICtrlSetState($curproxy, $GUI_DISABLE)
            GUICtrlSetState($numproxy, $GUI_DISABLE)
        EndIf
    EndIf
EndFunc  ;==>proxy

Func save()
    IniWrite("AutoViewer.ini", "Url", "url1", GUICtrlRead($url1))
    IniWrite("AutoViewer.ini", "Url", "url2", GUICtrlRead($url2))
    IniWrite("AutoViewer.ini", "Url", "url3", GUICtrlRead($url3))
    IniWrite("AutoViewer.ini", "Url", "url4", GUICtrlRead($url4))
EndFunc  ;==>save

Func numproxy()
    MsgBox(0, "Number of Proxies", "You have " & $inisize - 11 & " proxies in your list")
EndFunc  ;==>numproxy

Func curproxy()
    MsgBox(0, "Current Proxy", "The proxy being used is" & @LF & $ActProxy)
EndFunc  ;==>curproxy

Func about()
    MsgBox(0, "About", "AutoViewer" & @LF & "Version 1.4" & @LF & "Coded by: DvHrld" & @LF & "http://autoviewer.co.nr")
EndFunc  ;==>about

Func start()
    For $count = 11 To $inisize
        $line = FileReadLine("AutoViewer.ini", $count)
        RegWrite($key, "ProxyServer", "REG_SZ", $line)
        Sleep(1000)
        $oIE = _IECreate(GuiCtrlRead($url1), 0, 0, 0, 0); <-- Added a GuiCtrlRead
        Sleep(8000)
        __IENavigate($oIE, GuiCtrlRead($url2), 0, 4096); open in a new background tab
        Sleep(5000)
        __IENavigate($oIE, GuiCtrlRead($url3), 0, 4096); open in a new background tab
        Sleep(5000)
        __IENavigate($oIE, GuiCtrlRead($url4), 0, 4096); open in a new background tab
        Sleep(180000)
        ProcessClose("iexplore.exe")
        Sleep(2000)
    Next
EndFunc

Func stop()
    ProcessClose("iexplore.exe")
;~  Sleep(800)
EndFunc  ;==>stop


Func Terminate()
    ProcessClose("iexplore.exe")
;~  Sleep(800)
    Exit
EndFunc  ;==>Terminate
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
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...