Jump to content

melkortheevil

Members
  • Posts

    6
  • Joined

  • Last visited

melkortheevil's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. Hi, the example code below opens IE window on button click. I am trying to close the IE window on second click and break the running function. I am asking for help with the following issues: 1. If you don't wait long enough to see autoit web site loaded there is an error message in AutoIt cosole and the script will exit. I guess that's because $oIE doen't exist anymore. IE.au3 (586) : ==> Variable must be of type "Object". 2. If you wait long enough you can close IE but the function is still running as you can see in console. Is there a way to break the running function? #include <IE.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> Global $oIE, $oHWND Global $Form1, $Button1 Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Meteor SMS Agent v0.2", 304, 329, 246, 160) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $Button1 = GUICtrlCreateButton("Run IE", 48, 224, 83, 33) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetOnEvent(-1, "smssendbutton") GUISetState() $running = True $startsmssend = False While 1 Sleep(100) If $startsmssend Then smssend() $startsmssend = False EndIf WEnd Func smssendbutton() $sButtonText = GUICtrlRead ($Button1) If $sButtonText = "Run IE" Then ; Change the text on Button on click GUICtrlSetData($Button1, "STOP IE") Else GUICtrlSetData($Button1, "Run IE") EndIf $running = Not $running ;$running is False on first click If ($running = True) And ($startsmssend = True) Then _Quit() If $startsmssend = False then $startsmssend = True EndFunc ;==>smssendbutton Func smssend() ;THIS IS THE MAIN FUNCTION $oIE = _IECreate () ;$oIE = _IECreate ("https://www.mymeteor.ie/go/login") ;it's still loading, can't terminate it $oHWND = _IEPropertyGet($oIE, "hwnd") _IENavigate($oIE, "https://www.mymeteor.ie/go/login") _IENavigate($oIE, "http://www.autoitscript.com") For $ir = 0 To 1000 Sleep(50) ConsoleWrite($ir & @CRLF) Sleep(50) Next EndFunc Func _Quit() _IEQuit ($oIE) ;first try $oIE=0 ;_IEAction ( $oIE, "quit") ; second try ;If WinExists($oHWND) then $oIE.Quit ; third try ConsoleWrite ( "Done" ) EndFunc Func Quit() Exit EndFunc
  2. Thanks martin. I found that I can close IE window if $oIE = _IECreate() is used and _IENavigate after that. At the moment I have two issues not only with IE so maybe I will create a new thread with a code you taught me in this lesson Maybe you can still help me. Is it possible smoothly terminate a function? I am able,in some cases,kill IE window which is created at the begining of the main function. The problem is that the function is still running on backgroud. #include <IE.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> Global $oIE, $oHWND Global $Form1, $Button1 Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Meteor SMS Agent v0.2", 304, 329, 246, 160) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $Button1 = GUICtrlCreateButton("Run IE", 48, 224, 83, 33) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetOnEvent(-1, "smssendbutton") GUISetState() $running = True $startsmssend = False While 1 Sleep(100) If $startsmssend Then smssend() $startsmssend = False EndIf WEnd Func smssendbutton() If $startsmssend = True Then MsgBox(4160, "Information", "Function is already running!") $running = Not $running ;$running is False on first click If ($running = True) And ($startsmssend = True) Then _Quit() If $startsmssend = False then $startsmssend = True EndFunc ;==>smssendbutton Func smssend() ;THIS IS THE MAIN FUNCTION $oIE = _IECreate () ;$oIE = _IECreate ("https://www.mymeteor.ie/go/login") ;it's still loading, can't terminate it $oHWND = _IEPropertyGet($oIE, "hwnd") _IENavigate($oIE, "https://www.mymeteor.ie/go/login") _IENavigate($oIE, "http://www.autoitscript.com") For $ir = 0 To 1000 Sleep(50) ConsoleWrite($ir & @CRLF) Sleep(50) Next EndFunc Func _Quit() _IEQuit ($oIE) ;first try $oIE=0 ;_IEAction ( $oIE, "quit") ; second try ;If WinExists($oHWND) then $oIE.Quit ; third try ConsoleWrite ( "Done" ) EndFunc Func Quit() Exit EndFunc Issues 1. If you don't wait long enough to see autoit web site loaded there is an error message in AutoIt cosole. IE.au3 (586) : ==> Variable must be of type "Object". 2. If you wait long enough you can close IE but the function is still running.
  3. Thanks martin, I got your point. You are star. Nice solution. I slightly modified your code to implement Start/Stop functionaly with one button. $running = True $startsmssend = False While 1 Sleep(100) If $startsmssend Then smssend() GUICtrlSetData($Button1, "SendSMS") $startsmssend = False EndIf WEnd Func smssendbutton() $sButtonText = GUICtrlRead ($Button1) If $sButtonText = "Send SMS" Then ; Change the text on Button on click GUICtrlSetData($Button1, "STOP") Else GUICtrlSetData($Button1, "Send SMS") EndIf $running = Not $running ;$running is False on first click If ($running = True) And ($startsmssend = True) Then _Quit() $startsmssend = True EndFunc ;==>smssendbutton I have one additional question. How to close IE window created in main smssend() function? I am trying to cancel the process with the same button which calls _Quit() function. Bellow are the ideas which don't work for me now. Func _Quit() ;If WinExists($IEWnd) then $oIE.Quit ;_IEQuit ($oIE) ;_IEAction ( $oIE, "quit") EndFunc
  4. Friends, I am really desperate and I hope you can help me. I coded my first GUI script to send free SMS. Description: When $Button1 is pressed the main function starts. It takes about 2 minutes to complete because it loads few web pages and insert some data as logon credentials, recipient number and text message itself. 1. When the button is pressed the GUI is "frozen" until main function is completed. Is it possible to return the control to GUI and press the same button or other buttons to e.g. change global variable? 2. Is it possible to stop running function? I found many examples but all are related to very fast calculations. There is no calculation in my function it simply loads the web pages and retrieve/insert some data so I don't know if there is a place for any FOR or While loop. I tried to achieve this two goals with both "On Event" and "Case Switch" solution so my code is really dirty now. I am going to provide working concept. #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <GuiStatusBar.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Meteor SMS Agent v0.2", 304, 329, 246, 160) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") $file = GUICtrlCreateMenu("&File") $menu_exit = GUICtrlCreateMenuItem("Exit", $file) GUICtrlSetOnEvent(-1, "_Quit") $help = GUICtrlCreateMenu("Help") $menu_about = GUICtrlCreateMenuItem("About", $help) GUICtrlSetOnEvent(-1, "about") $hListBox = GUICtrlCreateList("", 192, 96, 89, 118, $LBS_STANDARD) $Button1 = GUICtrlCreateButton("Send SMS", 48, 224, 83, 33, $WS_GROUP) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") ;GUICtrlSetOnEvent(-1, "_StartStopButton") GUICtrlSetOnEvent(-1, "smssend") $Input1 = GUICtrlCreateInput("085", 16, 32, 89, 24, $ES_NUMBER) GUICtrlSetLimit(-1, 10) $Edit1 = GUICtrlCreateEdit("", 16, 96, 145, 121, BitOR($LBS_STANDARD, $WS_VSCROLL) ) GUICtrlSetLimit(-1, 160) GUICtrlSetData(-1, "") $Label1 = GUICtrlCreateLabel("Your phone number", 16, 8, 121, 20) $Label2 = GUICtrlCreateLabel("Message (160 chars)", 16, 72, 129, 20) $Label3 = GUICtrlCreateLabel("Contact List", 192, 72, 72, 20) $Input2 = GUICtrlCreateInput("", 192, 32, 57, 24, BitOR($ES_PASSWORD, $ES_NUMBER)) GUICtrlSetLimit(-1, 7) $Label4 = GUICtrlCreateLabel("PIN (MyMeteor)", 192, 8, 97, 20) $Progress1 = GUICtrlCreateProgress(50, 264, 77, 10) $Input3 = GUICtrlCreateInput("300 / 300", 216, 232, 57, 24,$ES_READONLY) $Label5 = GUICtrlCreateLabel("Free SMS", 216, 256, 64, 20) ;$help = GUICtrlCreateMenu("Help") ;$menu_about = GUICtrlCreateMenuItem("About", $help) $StatusBar = _GUICtrlStatusBar_Create($Form1, -1, "Ready") GUISetState(@SW_SHOW) While 1 sleep(100) WEnd Func smssend() ;THIS IS THE MAIN FUNCTION - it takes about 2 minutes to complete, It loads different web pages EndFunc Func _quit() exit EndFunc Func about() MsgBox(8192 + 262144 + 64, "Information about...", "I am desperate :)") EndFunc
  5. OK I solved this problem, I forgot to use admin rights. but now sometimes i got this error (and similar): $aSystemInfo[$i][15] = $objItem.EnableDayLightSavingTime^ERROR I have to ; this lines
  6. can you help me with remote computers? when i declare $cI_Compname = "****" other then my localhost i always get an error Line 2369 (File "C:\Program files\AutoIt3\Include\CompInfo.au3"): $colItems = $objWMIService^ERROR Error: Variable must be of type "Object" Example: #Include <Date.au3> Dim $System $cI_Compname = "TESTCOMP" _ComputerGetSystem($System) MsgBox(0, "Test _ComputerGetSystem", "Model: " & $System[1][22]) MsgBox(0, "Test _ComputerGetSystem", "Name: " & $System[1][49])
×
×
  • Create New...