close all other scripts whose names start with "race" Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
Gyro-Gearloose
Posts: 121
Joined: 03 Jan 2020, 16:13

close all other scripts whose names start with "race"

23 Jun 2020, 19:56

A compiled script script named "race-xyz.exe" is running. I want it to close or kill all other scripts whose names start with "race", of course not the running script.For example:
Race A.exe, Race B.exe, Race C.exe, Race D.exe. I want to kill or close all Races xyz without the calling script Race X, which cant kill itself anyway. I think.
Last edited by BoBo on 24 Jun 2020, 06:31, edited 1 time in total.
Reason: Moved to Gaming section.
User avatar
boiler
Posts: 17043
Joined: 21 Dec 2014, 02:44

Re: close all other scripts whose names start with "race"

23 Jun 2020, 20:20

Code: Select all

Skip := "X"
loop, 26
	if (Chr(64 + A_Index) != Skip)
		Process, Close, % "Race " Chr(64 + A_Index) ".exe"
User avatar
Gyro-Gearloose
Posts: 121
Joined: 03 Jan 2020, 16:13

Re: close all other scripts whose names start with "race"

24 Jun 2020, 03:38

Thank you @boiler. The fact is, my example was misleading. I've got a mostly working routine to loop through all active compiled scripts. Thank you @vsub. I'd like to close or kill all scripts whose name starts with "Race", Race scripts are named:
Race-Damned.exe
Race-Beach Party.exe
Race-Into the dam.exe
Race-Target.exe
... Just 4 out of 25. If I run one of these scripts it should close or kill all the other "Race"-scripts without further asking. Except the present active script, of course, which is a "Race"-script as well.
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: close all other scripts whose names start with "race"

24 Jun 2020, 04:15

Code: Select all

DetectHiddenWindows,on
#SingleInstance,Force

If !A_IsCompiled
{
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
}
}

WinGet,ID,List,ahk_class AutoHotkey
Loop, %ID%
{
ID := ID%A_Index%
WinGet,exe,ProcessName,ahk_id %ID%
IfInString,exe,Race
Process,Close,% exe
}
ExitApp
And btw,are you telling me that you have 25 scripts running?
User avatar
boiler
Posts: 17043
Joined: 21 Dec 2014, 02:44

Re: close all other scripts whose names start with "race"  Topic is solved

24 Jun 2020, 04:35

This will do it:

Code: Select all

for proc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
    if RegExMatch(proc.Name, "^Race .+\.exe", Proc)
		if (Proc != A_ScriptName)
			Process, Close, % Proc
User avatar
Gyro-Gearloose
Posts: 121
Joined: 03 Jan 2020, 16:13

Re: close all other scripts whose names start with "race"

24 Jun 2020, 05:10

@vsub. No, not at the same time. I'm working on route profiles for most of the special vehicle races at GTA online and have to choose the suitable profile within seconds. Some profiles are for testing purposes open in the editor, some are ready compiled for use. as it is hard to know, which code is being executed, I thought to have all but one closed would make it a lot easier.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: close all other scripts whose names start with "race"

24 Jun 2020, 06:33

@Gyro-Gearloose Vll gelingt es dir, deine Anfragen im Zusammenhang mit gaming-Scripten zukünftig im Gaming-Forum zu platzieren.
Das es sich bei GTA um ein game handelt ist schließlich kein Geheimnis. Danke.

BoBo
User avatar
Gyro-Gearloose
Posts: 121
Joined: 03 Jan 2020, 16:13

Re: close all other scripts whose names start with "race"

24 Jun 2020, 07:29

@bobo. Es tut mir leid. Mir erschließt sich die Sinnhaftigkeit des Verweises auf das Gaming-Forum nicht, solange es sich nicht um etwas Gaming-Spezifisches handelt. Zu erfahren, welche Scripte laufen, und bestimmte Scripte zu schließen, erscheint mir eine keineswegs auf Spiele beschränkte Anforderung.
User avatar
Gyro-Gearloose
Posts: 121
Joined: 03 Jan 2020, 16:13

Re: close all other scripts whose names start with "race"

24 Jun 2020, 15:08

@boiler. Could I enclude your code in a Race-script in a way, that it is always executed by calling the script and therefore close all other Race-Executables? Forgive me for not trying out before asking. It is so thrilling, I can hardly wait to test it. I'll do my best to understand your code. Even if it takes some days.
User avatar
boiler
Posts: 17043
Joined: 21 Dec 2014, 02:44

Re: close all other scripts whose names start with "race"

24 Jun 2020, 15:35

Yes, you can #Include it at the top of a script, and when you run any script that includes it, it will kill all other Race script executables except itself. However, use the version below because I see in one of your posts that the word Race isn’t followed by a space like in your first post, but with dashes. I removed the space in the version below so that it will kill all processes that start with the 4 letters Race and are followed by anything else. I also changed a variable name in the version below to make it more clear.

Code: Select all

 for proc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
    if RegExMatch(proc.Name, "^Race.+\.exe", RaceProc)
		if (RaceProc != A_ScriptName)
			Process, Close, % RaceProc
Description of how it works: Queries the list of all processes which results in an object called proc (as shown in example #5 in the Process documentation. The property called Name of the proc object is the process name. Each process name is checked to see if it meets the format “Race....exe”. If it does, it checks to make sure it’s not it’s own process. If it is indeed some other process, that process is killed.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 63 guests