Simplest to way to run several ahk scripts with one script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Simplest to way to run several ahk scripts with one script?

21 Nov 2019, 23:22

Hello!

I've been looking around and coudln't find any simple guides for this. I found something that made an .exe file and removed tray icons, I don't want that.

Anyone know how to run a number of scripts somehow through for example a ahk script that you run which exits once all the scripts you want are excecuted?
I want them to run in admin mode.
User avatar
lmstearn
Posts: 695
Joined: 11 Aug 2016, 02:32
Contact:

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 03:39

Hi Maxkill. :)
It can be done with the Run or Runwait command. There's a few examples. Get the ahk_id's from the running scripts with a timer to monitor their status.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 07:56

Like this?

Code: Select all

+f3:: 
Run, %ComSpec% /c dir /b > C:\Users\Username5555\Music\script1.ahk && C:\Users\Username5555\Music\script2.ahk && C:\Users\Username5555\Music\script2.ahk && C:\Users\Username5555\Music\script2.ahk
return
(Username555 is your computer name)
99.8% chance of being wrong.
Felt that the manual was unclear. I don't get why they don't give a actual example like above, if you have several scripts you want to run paste the path of each script incl full file name with && between each? The text does not show this in a simple to understand way.
This line 'Run, %ComSpec% /c dir /b > C:\list.txt && type C:\list.txt && pause' has two adresses in it with the same file, I'm guessing the last part is to do some type of action in the file once it's run but certainly not sure.

Then there's the aspect of incoorporating run as admin function

Code: Select all

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}

MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%
Absloutely no idea how to merge these two together for a full script.
User avatar
lmstearn
Posts: 695
Joined: 11 Aug 2016, 02:32
Contact:

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 08:14

That's possible. There's also Guest10's script at this thread.
Running your script as admin with the code in your post allows you to run scripts from cmd as admin as well.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 08:33

lmstearn wrote:
22 Nov 2019, 08:14
That's possible. There's also Guest10's script at this thread.
Running your script as admin with the code in your post allows you to run scripts from cmd as admin as well.

Code: Select all

DetectHiddenWindows, On
Gui, +Resize -MaximizeBox
Gui, Add, ListView, w500 h200 vlvwList hwndhlvwList gListClick, PID|Script Path|Working Set|Peak Working Set|Page File|Peak Page File
Gui, Add, Button, y+6 xp w247 hwndhRefresh gRefresh, Refresh list
Gui, Add, Button, yp x+6 wp hwndhEndProc gEndProc, End associated process
Gui, Show
Sleep 200 ; Give time for Anchor to catch on
RefreshList()
Return
GuiClose:
ExitApp
GuiSize:
Anchor(hlvwList, "wh")
Anchor(hRefresh, "y w0.5")
Anchor(hEndProc, "x0.5 y w0.5")
Return
Refresh:
RefreshList()
Return
ListClick:
If (A_GuiEvent <> "DoubleClick")
Return
EndProc:

i := LV_GetNext()
WinKill, % "ahk_id " AHKWindows%i%
RefreshList()

Return
RefreshList() {
Global

LV_Delete()
WinGet, AHKWindows, List, ahk_class AutoHotkey

Loop %AHKWindows% {

; Get process ID
WinGet, AHKWindows%A_Index%_PID, PID, % "ahk_id " AHKWindows%A_Index%
GetProcessMemoryInfo(AHKWindows%A_Index%_PID)

; Get memory info
LV_Add(0, AHKWindows%A_Index%_PID, GetScriptPathFromHwnd(AHKWindows%A_Index%)
, Round(GetProcessMemoryInfo(0,12) / 1024) " K", Round(GetProcessMemoryInfo(0,8) / 1024) " K"
, Round(GetProcessMemoryInfo(0,32) / 1024) " K", Round(GetProcessMemoryInfo(0,36) / 1024) " K")
}

Loop 6
LV_ModifyCol(A_Index, "AutoHdr")

; Get columns width
iColWidth := 0
Loop 6 {
SendMessage, 4125, A_Index - 1, 0,, ahk_id %hlvwList%
iColWidth += ErrorLevel
}

; Set main width in accordance to column width
iWidth := iColWidth + 24
Gui, Show, w%iWidth%
}
GetScriptPathFromHwnd(hwnd) {
WinGetTitle, win, ahk_id %hwnd%
;msgbox, % "win is: " win
path := "Run, %ComSpec% /c dir /b > C:\Users\Username5555\Music\script1.ahk && C:\Users\Username5555\Music\script2.ahk && C:\Users\Username5555\Music\script3.ahk && C:\Users\Username5555\Music\script4.ahk"
;msgbox, % "path: " path
If (win = path)
{
;MsgBox, Check!
; Some code here!
Sleep, 100
ExitApp
}
Return RegExMatch(win, ".*(?= - AutoHotkey v[0-9\.]+)", ret) ? ret : win
}
GetProcessMemoryInfo(pid, info=-1) {
Static uMemCounters := 0

; Check if we just want info from the struct
If (info <> -1)
Return NumGet(uMemCounters, info)
Else {

; Open the process with PROCESS_QUERY_INFORMATION and PROCESS_VM_READ
h := DllCall("OpenProcess", "UInt", 0x0410, "UInt", 0, "UInt", pid)

; Put info into struct
If Not uMemCounters ; Check if it hasn't already been initialized
VarSetCapacity(uMemCounters, 40)
DllCall("Psapi.dll\GetProcessMemoryInfo", "UInt", h, "UInt", &uMemCounters, "UInt", 40)

; Done!
DllCall("CloseHandle", "UInt", h)
}
}
; Anchor() by Titan
; http://www.autohotkey.com/forum/viewtopic.php?t=4348
Anchor(i, a = "", r = false) {
static c, cs = 12, cx = 255, cl = 0, g, gs = 8, z = 0, k = 0xffff, gx = 1
If z = 0
VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), z := true
If a =
{
StringLeft, gn, i, 2
If gn contains :
{
StringTrimRight, gn, gn, 1
t = 2
}
StringTrimLeft, i, i, t ? t : 3
If gn is not digit
gn := gx
}
Else gn := A_Gui
If i is not xdigit
{
GuiControlGet, t, Hwnd, %i%
If ErrorLevel = 0
i := t
Else ControlGet, i, Hwnd, , %i%
}
gb := (gn - 1) * gs
Loop, %cx%
If (NumGet(c, cb := cs * (A_Index - 1)) == i) {
If a =
{
cf = 1
Break
}
Else gx := A_Gui
d := NumGet(g, gb), gw := A_GuiWidth - (d >> 16 & k), gh := A_GuiHeight - (d & k), as := 1
, dx := NumGet(c, cb + 4, "Short"), dy := NumGet(c, cb + 6, "Short")
, dw := NumGet(c, cb + 8, "Short"), dh := NumGet(c, cb + 10, "Short")
Loop, Parse, a, xywh
If A_Index > 1
	 av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField)
	 , d%av% += (InStr("yh", av) ? gh : gw) * (A_LoopField + 0 ? A_LoopField : 1)
DllCall("SetWindowPos", "UInt", i, "Int", 0, "Int", dx, "Int", dy, "Int", dw, "Int", dh, "Int", 4)
If r != 0
DllCall("RedrawWindow", "UInt", i, "UInt", 0, "UInt", 0, "UInt", 0x0101) ; RDW_UPDATENOW | RDW_INVALIDATE
Return
}
If cf != 1
cb := cl, cl += cs
If (!NumGet(g, gb)) {
Gui, %gn%:+LastFound
WinGetPos, , , , gh
VarSetCapacity(pwi, 68, 0), DllCall("GetWindowInfo", "UInt", WinExist(), "UInt", &pwi)
, NumPut(((bx := NumGet(pwi, 48)) << 16 | by := gh - A_GuiHeight - NumGet(pwi, 52)), g, gb + 4)
, NumPut(A_GuiWidth << 16 | A_GuiHeight, g, gb)
}
Else d := NumGet(g, gb + 4), bx := d >> 16, by := d & k
ControlGetPos, dx, dy, dw, dh, , ahk_id %i%
If cf = 1
{
Gui, %gn%:+LastFound
WinGetPos, , , gw, gh
d := NumGet(g, gb), dw -= gw - bx * 2 - (d >> 16), dh -= gh - by - bx - (d & k)
}
NumPut(i, c, cb), NumPut(dx - bx, c, cb + 4, "Short"), NumPut(dy - by, c, cb + 6, "Short")
, NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short")
Return, true
}
Like this?
And just running the ahk script as admin will run all the scripts as admin?
User avatar
lmstearn
Posts: 695
Joined: 11 Aug 2016, 02:32
Contact:

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 08:53

Yes, they''ll all have admin rights. Haven't tested that script- but it looks all right to go. Post back if there are any issues with it,- and good luck!
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
fwejifjjwk2
Posts: 89
Joined: 10 Aug 2019, 01:49

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 20:31

@maxkill
You code just destroy my scirpt. Please edit.

Is this not simple enough?

Code: Select all

Run, "C:\Users\example1.ahk"
Run, "C:\Users\example2.ahk"
return
I think run all ahk script in same directory can do what you want. Or use #Include
Last edited by fwejifjjwk2 on 22 Nov 2019, 21:41, edited 4 times in total.
gregster
Posts: 9034
Joined: 30 Sep 2013, 06:48

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 20:36

@fwejifjjwk2: Afaik, the code (that you reported... btw, the report function is not really meant to report presumably broken code; malicious code you can report, of course) works - it is a copy of this code in the docs: https://www.autohotkey.com/docs/commands/Run.htm#RunAs

Please note that part of the question was running 'as admin'.
fwejifjjwk2
Posts: 89
Joined: 10 Aug 2019, 01:49

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 20:45

@gregster
I talking about this code.

Code: Select all

Run, %ComSpec% /c dir /b > "myscript1.ahk" && "myscript2.ahk"
Also if use this way (follow document)

Code: Select all

Run, %ComSpec% /c dir /b > "myscript1.ahk" && type "myscript2.ahk" && pause
I write this code in script name it main.ahk. Run it than myscript1 content become "dance main.ahk".
Last edited by fwejifjjwk2 on 22 Nov 2019, 21:14, edited 6 times in total.
gregster
Posts: 9034
Joined: 30 Sep 2013, 06:48

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 20:54

Your report was kind of murky about that fact.

But obviously he was asking if that's the right syntax - of course, you should be careful if you run command line commands, especially if it's not really clear, what the code does or if it works... so what does this code actually do ? Some details might help others to avoid your problems. What is dance main.ahk ? It's nowhere mentioned...
fwejifjjwk2
Posts: 89
Joined: 10 Aug 2019, 01:49

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 21:11

@gregster
I already test this. I think something wrong. (run as admin or not)
In c:\test have 3 script. Which is main.ahk a.ahk b.ahk
In main.ahk

Code: Select all

Run, %ComSpec% /c dir /b > C:\test\a.ahk && C:\test\b.ahk
Return
In a.ahk and b.ahk

Code: Select all

msgbox, 1
Run main.ahk
a.ahk content become

Code: Select all

a.ahk
b.ahk
main.ahk
Last edited by fwejifjjwk2 on 22 Nov 2019, 21:29, edited 2 times in total.
gregster
Posts: 9034
Joined: 30 Sep 2013, 06:48

Re: Simplest to way to run several ahk scripts with one script?

22 Nov 2019, 21:23

Thanks for the feedback!
Yes, it looks like it would redirect the result of dir into a script file - or something similar. This code is probably not very useful and not what the original poster intended.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Peiya, ShatterCoder and 313 guests