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.
close all other scripts whose names start with "race" Topic is solved
- Gyro-Gearloose
- Posts: 121
- Joined: 03 Jan 2020, 16:13
close all other scripts whose names start with "race"
Last edited by BoBo on 24 Jun 2020, 06:31, edited 1 time in total.
Reason: Moved to Gaming section.
Reason: Moved to Gaming section.
Re: close all other scripts whose names start with "race"
Code: Select all
Skip := "X"
loop, 26
if (Chr(64 + A_Index) != Skip)
Process, Close, % "Race " Chr(64 + A_Index) ".exe"
- Gyro-Gearloose
- Posts: 121
- Joined: 03 Jan 2020, 16:13
Re: close all other scripts whose names start with "race"
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.
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.
Re: close all other scripts whose names start with "race"
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
Re: close all other scripts whose names start with "race" Topic is solved
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
- Gyro-Gearloose
- Posts: 121
- Joined: 03 Jan 2020, 16:13
Re: close all other scripts whose names start with "race"
@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.
Re: close all other scripts whose names start with "race"
@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
Das es sich bei GTA um ein game handelt ist schließlich kein Geheimnis. Danke.
BoBo
- Gyro-Gearloose
- Posts: 121
- Joined: 03 Jan 2020, 16:13
Re: close all other scripts whose names start with "race"
@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.
- Gyro-Gearloose
- Posts: 121
- Joined: 03 Jan 2020, 16:13
Re: close all other scripts whose names start with "race"
@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.
Re: close all other scripts whose names start with "race"
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.
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.
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
Who is online
Users browsing this forum: No registered users and 63 guests