Jump to content

Config to change script's behavior


Recommended Posts

Hello!

So I made a script that closes the program, then reopens it. Here's the source:

$qwerty1 = "C:\Users\3D\Desktop\qweqwe\1\qwerty1.exe"
$qwerty2 = "C:\Users\3D\Desktop\qweqwe\2\qwerty2.exe"
$qwerty3 = "C:\Users\3D\Desktop\qweqwe\3\qwerty3.exe"

While 1
    If ProcessExists("qwerty1.exe") Then
        ProcessClose("qwerty1.exe")
    EndIf
    If ProcessExists("qwerty2.exe") Then
        ProcessClose("qwerty2.exe")
    EndIf
    If ProcessExists("qwerty3.exe") Then
        ProcessClose("qwerty3.exe")
    EndIf
Run($qwerty1)
Run($qwerty2)
Run($qwerty3)
WEnd

Sometimes I instead want to use this:

$qwerty1 = "C:\Users\3D\Desktop\qweqwe\1\qwerty1.exe"
$qwerty2 = "C:\Users\3D\Desktop\qweqwe\2\qwerty2.exe"

While 1
    If ProcessExists("qwerty1.exe") Then
        ProcessClose("qwerty1.exe")
    EndIf
    If ProcessExists("qwerty2.exe") Then
        ProcessClose("qwerty2.exe")
    EndIf
Run($qwerty1)
Run($qwerty2)
WEnd

My question is, how can I make a config in which I can choose the amount of "qwerty" used, for example qwerty=3. Also a first time-open config with a GUI and the specified amount of "qwerty"s used.

Also, is there a way of making the script shorter?

Thank you.

Edited by n4n0
Link to comment
Share on other sites

  • Moderators

I would suggest using processlist. If you truly do have executables that close in naming, you could do something like this:

 

$aList = ProcessList()
    For $i = 1 To $aList[0][0]
        If StringInStr($aList[$i][0], "qwerty") Then ProcessClose($aList[$i][0])
    Next

If you aren't sure of the number of executable files, you could use the command line parameters to set it:

$x = $CmdLine[1]
MsgBox(0, "", $x)

Check the help file for more on Command Line Parameters

The way you have it written above, however, you're closing both, then running both, in a constant loop. Can you please explain in more detail what you're trying to accomplish?

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I am trying to close all of them, then opening them all again. That's the sole purpose of the script. The loop is infinite with a delay between the loops. The amount of "qwerty" varies and I want a config to determinte the exact amount.

Edited by n4n0
Link to comment
Share on other sites

  • Moderators

n4n0,

May one enquire as to why you need to perform this rather strange action?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Primary reason to why I made a new thread was to learn more about AutoIt and making configs with it. 

The scripts restarts the applications (qwerty) in case they freeze or crash (not when they do).

Edited by n4n0
Link to comment
Share on other sites

  • Moderators

But, how are you deciding the app has frozen or crashed? The way you are approaching it, it will simply continue to close and then relaunch those three applications, regardless of what they are doing.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Exactly, doesn't matter, just restart the application, making it restart only when it crashes/freezes is something I will work with later on. What I'm focusing on now is the config and how to do it, but I have honestly no idea.

Link to comment
Share on other sites

What kind of config are you looking for? A variable early in the script that you set manually before running? A GUI with a number and an up/down control? A commandline parameter to be able to run it from a batchfile? An ini-file?

By the way, if you're going to test your code like this in that loop, please add something like Sleep(10000) to have your script at least sleep 10 seconds before killing and running the applications. Otherwise, your system might become unstable. Constantly killing and running applications as fast as your machine can handle is quite useless.

Edited by SadBunny
typo

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

If opening for the first time, I want a simple GUI with a textbox where you simply type the number, 3, 4, 5 or whatever, then press "Ok". The script is simply exectuable by double clicking the script which launches and reads the config if it's already created. 

I have a delay in the loop.

Edit: added ' #include "qwerty.ini" ' and "$qwerty=2" in the .ini file, which is used by the script ^^

Edited by n4n0
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...