Jump to content

Recommended Posts

Hi! Thanks for a great forum which I have learned the little I know so far..

At my job we use Autoit to automate a lot of tasks in our ERP for mainly masterdata but also other tasks. We run  all scripts inside scite(F5), and all scripts have validations, progressbar and a tab separated datafile.txt We use a standard main function file and various other function files for the different tasks that we include in the scripts that fetches those from shared folder with restricted access.

For the first time I am creating an .exe the user can run on the computer which I have done and the file open dialog where the user choose the datafile work ok for me that have access to the function scripts, but the user has not. (user has access to and updates datafile.txt manually from live-excel  copy/paste)

Now that you know what I do, the next step is to create a simple gui that contains the script and the function scripts.. And maybe buttons for "run script" and "stop script" (effectivly just "home" in a button)

Since I am a novice and have no experience creating gui I have looked into the examples and some graphical programs to create them, but can not find what I need.. Kodi, Guibuilder and others have come up in my search but I do not know what to do..

Can anyone of you experts point me in the right direction?

Link to post
Share on other sites

In Scite just run the Koda Form Designer from the tools menu. From there you can create the outline for a simple GUI control. Click on the controls you may need and drop them on the design form. Try it, you may find it fairly intuitive, Search  google for autoit koda form designer tutorial where you will find some Youtube tutorials.

Phil Seakins

Link to post
Share on other sites

Thanks Phil!

Just watched a couple of Tuts Teach's videos about this and I was surprised both that it is built into scite, but also how easy it was to use the Case functions.. 😀

Now I need to figure out how to have the three scripts inside the gui... or maybe I could paste them into the script and use "Global" instead of "include" so I can compile the whole thing into one .exe?

Or is it possible to put more than one au3 file into one .exe?

-Sorry if my questions are so basic, but that is mostly because we use already made scripts and mostly just copy/paste or change only minor things such as validations and keystrokes and movements.. So I have not started from the beginning which I suffer from now.. lol

Link to post
Share on other sites

I am no expert with AutoIt GUIs. Your scripts can probably be set up as individual functions within your script, each one triggered by a button on the main form.

Probably best to wait for someone more experienced to help you with this. They will be along in a few hours - different time zone from me.

Phil Seakins

Link to post
Share on other sites
39 minutes ago, Axiom said:

Now I need to figure out how to have the three scripts inside the gui... or maybe I could paste them into the script and use "Global" instead of "include" so I can compile the whole thing into one .exe?

Or is it possible to put more than one au3 file into one .exe?

If you #include a .au3 file in your script, the included file will become part of the 'main' script. - #Include <Filename.au3> is basically just a short way of telling AutoIt to "read text in Filename.au3 and insert all lines here". 

All files you included with #include will be part of your .exe automatically.

How you actually "include" the functionality inside your GUI highly depends on how your function scripts are set up. If they are standalone-scripts, to perform data you could just FileInstall(...) and Run(...) them. Please see the Help File for autoitscript.com/autoit3/docs/intro/running.htm for details.

If they are actual function collections, you can just call those functions in your GUI's "Message Loop" - that is where you handle the button clicks.

 

Here's an example of a Script with 2 simple buttons which would call functions from two different include files:

Spoiler

Example_Gui.au3

#include <GUIConstantsEx.au3>
#include "MyFunctionScript1.au3"
#include "MyFunctionScript2.au3"

$hGUI = GUICreate("")
$hButton1 = GUICtrlCreateButton("Function Script 1", 0, 0)
$hButton2 = GUICtrlCreateButton("Function Script 2", 0, 30)
GUISetState()

; ...

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton1
            _FunctionScript1_DoAllTheStuff()
        Case $hButton2
            _FunctionScript2_DoAllTheStuff()

    EndSwitch
WEnd

MyFunctionScript1.au3:

Func _FunctionScript1_DoAllTheStuff()
    Sleep(500)
    MsgBox(0,"","I am Function Script 1")
EndFunc

MyFunctionScript2.au3:

Func _FunctionScript2_DoAllTheStuff()
    MsgBox(0,"","I am Function Script 2")
    Sleep(500)
EndFunc

 

 

Link to post
Share on other sites

Additional note :

AutoIt already provides a variety of GUI scripts for demonstration purposes.

One of them shows the different GUI elements in some sort of collage, see ..\AutoIt3\Examples\GUI\SampleControls.au3

You will find more, if you take a look in :  ..\AutoIt3\Examples\GUI\Advanced\  (all runnable).

You may or may not use a form designer like KODA, that is a question of individual preference. I haven't used KODA myself yet, but that doesn't mean it's an unsuitable tool.

Feel free to ask further questions before you move in the wrong direction :).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

Hi again! 

I decided to go for Koda for now, mostly for the ease of use and because I have a deadline to deliver an executable.

I actually found out that I could use the gui to handle all of the scripts I use.

Each script gets buttons for run, instruction and inputfile.

And I add pop-up progressbar, filedialouge and logfiles to each sctipt

The gui does not look exactly like win10 but I created icon, logotype and colored buttons.. so I am quite pleased.. And very grateful for your help.

A question: can i have a script like:

if ProcessExists("myscript1.exe") Then

    ProcessClose("myscript1exe"

..For closing a specific script?

Could I also list several and close them?

Link to post
Share on other sites

I'm not sure a process related function is the best way to end a script.
Is there a reason why you need to ProcessClose your own scripts?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

@water I don't think Axiom wants to close the script he is in.

1 hour ago, Axiom said:

ProcessClose("myscript1exe"

Have you tried the help? Position your cursor over "ProcessClose" and press F1. The help will tell you all you need to know about this function including examples. And, yes, you can have a script like your example.

Phil Seakins

Link to post
Share on other sites
53 minutes ago, water said:

I'm not sure a process related function is the best way to end a script.
Is there a reason why you need to ProcessClose your own scripts?

It is.exe files started by my.exe gui and they run until they are finished with their inputfiles.. so I want to be able to shut down the programs started from the gui if something goes wrong. Bare in mind that this should be run by users without autoit programs.

Link to post
Share on other sites
18 minutes ago, Axiom said:

Could I also list several and close them?

[...]

It is.exe files started by my.exe gui

Here is an example to close a list of processes (your .exe files).

#include <Array.au3>

; List of processes that should be closed :
Global $aMyProcesses = StringSplit("myscript1.exe;myscript2.exe;myscript3.exe", ";", 1)
_ArrayDisplay($aMyProcesses, "MyProcesses") ; *** just for test

Global $aProcessList = ProcessList()
For $i = 1 To $aProcessList[0][0]
    For $j = 1 To $aMyProcesses[0]
        If $aProcessList[$i][0] = $aMyProcesses[$j] Then
            ConsoleWrite("+ >>> Process " & $aMyProcesses[$j] & "  found" & @CRLF) ; *** just for test
            If ProcessClose($aMyProcesses[$j]) Then
                ConsoleWrite("> >>> Process " & $aMyProcesses[$j] & " closed" & @CRLF) ; *** just for test
                Sleep(1000)
            Else
                ConsoleWrite("! >>> Process " & $aMyProcesses[$j] & " not closed" & @CRLF) ; *** just for test
            EndIf
        EndIf
    Next
Next

However, as @water already wrote, it is not necessarily the best practice.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

@pseakins As Axiom uses "myscript1.exe" in his example I assume he wants to close his own scripts.

I suggest to do it the other way round. Grab the Process-ID of your GUI script (macro @AutoItPID) and pass it as parameter to the scripts you start.
Then let your scripts check if the main process still exists (ProcessExist). If not end the script.
So you just need to end the GUI and all other scripts will end automatically.
The check can either be done in a loop or by Adlibregister.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites
34 minutes ago, water said:

So you just need to end the GUI and all other scripts will end automatically

That's a good idea but it may not cover cases where the script gets stuck in a loop or blocked for some reason unless the script contains some kind of watchdog interrupt which looks out for the main GUI ending as you suggest.

Phil Seakins

Link to post
Share on other sites

For this cases you use Adlibregister. It interrupts your script every n milliseconds and calls a function. There you check for the master script and exit if needed. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites
22 minutes ago, water said:

For this cases you use Adlibregister. It interrupts your script every n milliseconds and calls a function. There you check for the master script and exit if needed. 

Do not remember why, but there where something that prevented us to use Adlibregister.. 

All of our scripts uses "Send" one or more times per second and I wonder if maybe the close idle application described here can do the trick? 

 

Link to post
Share on other sites

Running multiple scripts at the same time using Send might be dangerous. Send simulates keystrokes to the active window.
The user or other scripts might steal the focus - then your script does not run as expected.

(Without knowing the software you use) I suggest to either use Control* functions or an API provided by the vendor of your ERP software.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites
10 hours ago, water said:

Running multiple scripts at the same time using Send might be dangerous. Send simulates keystrokes to the active window.
The user or other scripts might steal the focus - then your script does not run as expected.

(Without knowing the software you use) I suggest to either use Control* functions or an API provided by the vendor of your ERP software.

I understand, but we never run more than one script on one computer at the time.. other than the planned gui to start/stop other scripts in exe.

Made two guis today and here is a screenshot(in Swedish)

 

87416BA9-A390-477C-A8C9-7B6E7C04855A.jpeg

Link to post
Share on other sites

Looks good :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites
2 minutes ago, Axiom said:

but we never run more than one script on one computer at the time

Then you may want to take a look at the _Singleton function as well. This prevents a script from being executed multiple times.

I am still convinced, that @water 's approach is more reliable. But since you have to obey to a deadline, as you say, your main focus is probably to get a result as fast as possible, right  ;)?

By the way : Did my script for closing multiple processes help you any further ?

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
1 hour ago, Musashi said:

Then you may want to take a look at the _Singleton function as well. This prevents a script from being executed multiple times.

I am still convinced, that @water 's approach is more reliable. But since you have to obey to a deadline, as you say, your main focus is probably to get a result as fast as possible, right  ;)?

By the way : Did my script for closing multiple processes help you any further ?

The "close multiple" is no longer needed since I have decided on another approach.

I think I may have described our way of working a bit unclear.. Until now we have just executed our au3 scripts by opening them in scite and F5. 95% of the scripts does tasks in our ERP and mainly masterdata and inventory adjustments, but also like the one today for creating transfers of all the equipment in a location to another.

But I want in the future to make copys of all scripts as .exe and run them from a common gui like the one test in the screenshot, and in groups with buttons for instructions, inputfile, run, stop and logs.

We do not have any sign on in the scripts but the user has to do sso in erp manually, so in that way no one can "do more" than their user profile allows.

The whole idea is to make it more "ease of use" and we can have groups of script  runners, developers and admins.

Btw the erp is Axiom (Version of Wynnes Rentalman) and is an AS400 with a JavaScript roleplay on top. 

I also plan to create scripts for getting data from a live-excel or PowerBi and creating autoit inputfiles in .txt, and script for buying in JCat, and script for stocktaking and more.. 🤪

Thanks again for all help.. ..I have a week of work starting tomorrow and I will start mounting our new garage port and be riding my motorcycle too 🏍💨

0DEFC5E5-7FF4-41BF-A95A-C4A5930B7469.jpeg

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

    No registered users viewing this page.

×
×
  • Create New...