Axiom Posted February 27, 2021 Share Posted February 27, 2021 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 comment Share on other sites More sharing options...
pseakins Posted February 27, 2021 Share Posted February 27, 2021 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. Axiom 1 Phil Seakins Link to comment Share on other sites More sharing options...
Axiom Posted February 27, 2021 Author Share Posted February 27, 2021 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 comment Share on other sites More sharing options...
pseakins Posted February 27, 2021 Share Posted February 27, 2021 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. Axiom 1 Phil Seakins Link to comment Share on other sites More sharing options...
SEuBo Posted February 27, 2021 Share Posted February 27, 2021 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 Axiom, FrancescoDiMuro and Musashi 2 1 AutoIt Examples/UDF's:Generate Function at Runtime using IRunningObjectTable / AutoItObjectVery Simple Inter-Process Communication (using AutoItObject Pure AutoIt) Link to comment Share on other sites More sharing options...
Musashi Posted February 27, 2021 Share Posted February 27, 2021 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 . FrancescoDiMuro and Axiom 2 "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 comment Share on other sites More sharing options...
Axiom Posted March 1, 2021 Author Share Posted March 1, 2021 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 comment Share on other sites More sharing options...
water Posted March 1, 2021 Share Posted March 1, 2021 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 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 Link to comment Share on other sites More sharing options...
pseakins Posted March 1, 2021 Share Posted March 1, 2021 @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. Axiom 1 Phil Seakins Link to comment Share on other sites More sharing options...
Axiom Posted March 1, 2021 Author Share Posted March 1, 2021 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 comment Share on other sites More sharing options...
Musashi Posted March 1, 2021 Share Posted March 1, 2021 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. "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 comment Share on other sites More sharing options...
water Posted March 1, 2021 Share Posted March 1, 2021 @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. Musashi 1 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 Link to comment Share on other sites More sharing options...
pseakins Posted March 1, 2021 Share Posted March 1, 2021 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 comment Share on other sites More sharing options...
water Posted March 1, 2021 Share Posted March 1, 2021 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 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 Link to comment Share on other sites More sharing options...
Axiom Posted March 2, 2021 Author Share Posted March 2, 2021 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 comment Share on other sites More sharing options...
water Posted March 2, 2021 Share Posted March 2, 2021 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 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 Link to comment Share on other sites More sharing options...
Axiom Posted March 2, 2021 Author Share Posted March 2, 2021 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) Link to comment Share on other sites More sharing options...
water Posted March 2, 2021 Share Posted March 2, 2021 Looks good Axiom 1 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 Link to comment Share on other sites More sharing options...
Musashi Posted March 2, 2021 Share Posted March 2, 2021 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 ? "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 comment Share on other sites More sharing options...
Axiom Posted March 2, 2021 Author Share Posted March 2, 2021 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 🏍💨 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now