Jump to content

Recommended Posts

Posted

Hello i am making a script. The main problem is that script is looping when process is found. I want that script open only 1 GUI when process it's recognized.

Here is script:

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

while 1
If ProcessExists("notepad.exe") Then ; Check if the Notepad process is running.

gui1()

Func gui1()
while 1
$oIE = ObjCreate("Shell.Explorer.2")

    ; Create a simple GUI for our output
    GUICreate("Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))
    GUICtrlCreateObj($oIE, 10, 40, 600, 360)

    GUISetState(@SW_SHOW) ;Show GUI

    $oIE.navigate("http://www.autoitscript.com")
 WEnd
EndFunc   ;==>gui

Else
    sleep(10000)
endif
WEnd

Thanks for help! 

Posted (edited)

Remove the loop wrapping your GUI... and add e.g a flag to be toggled when the process is found / not found.

Edited by FireFox
Posted

What is While/WEnd infunction gui1 for?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

That's nothing i was testing something. How you mean flag to be toggled? Im new in autoit ..

Program must all the time check if process exist if not do nothing, if exist than open GUI.

Thanks for answers

Posted (edited)

I didn't see your func is inside the loop. Read the helpfile with its examples and you will see how things work : it's outside everything.

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $fExists = False

While 1
    If ProcessExists("notepad.exe") Then ; Check if the Notepad process is running.
        If Not $fExists Then
            $fExists = True
            gui1()
        EndIf
    ElseIf $fExists Then
        $fExists = False
        Sleep(100)
    EndIf
WEnd

Func gui1()
    $oIE = ObjCreate("Shell.Explorer.2")

    ; Create a simple GUI for our output
    GUICreate("Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))
    GUICtrlCreateObj($oIE, 10, 40, 600, 360)

    GUISetState(@SW_SHOW) ;Show GUI

    $oIE.navigate("http://www.autoitscript.com")
EndFunc   ;==>gui1
Br, FireFox. Edited by FireFox
Posted

I tested it on 2 computers right now, on windows 7 and 8. 

On both i get loop when notepad is opened.

How is that possible that u don't get it ?

Thanks for answer

Posted

Oh i didn't saw that you edited your code!

I wanna ask why i can't close window "Embedded Web control Test" with "Exit" at top right corner of window?

Thanks

Posted (edited)

It's not magic, you need to tell the GUI you want the script to Exit when you click on the close button.

Look at the helpfile please (GUICreate).

Edited by FireFox

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
  • Recently Browsing   0 members

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