Run .bat on exit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
eric04h
Posts: 3
Joined: 25 Jul 2018, 02:26

Run .bat on exit

25 Jul 2018, 03:01

Alright, very new to all of this but seem to be needing it a lot for programing my arcade cabinet, but cannot figure this one out.

Ok, so I have a .bat file that opens application1.exe, enabledriver.bat, and ahkscript.exe

Would it be possible to program the ahkscript to run another .bat file once it detects application1.exe closes?

Basically the first .bat that is ran enables a driver via devcon, but once application1 closes, I need it to run disabledriver.bat and then proceed to close ahkscript.exe as well.

I have this below that I found for closing the ahkscript when application1 closes, but no idea how to get it o run .bat before quitting ahkscript.exe

Any help would be greatly appreciated! Thank you!

Code: Select all

 #NoEnv
#SingleInstance, Force
#Persistent
SetTitleMatchMode, 2
DetectHiddenWindows, On
 
SetTimer, ProcessCheckTimer, 3000
Return
 
ProcessCheckTimer:
Process, Exist, application1.exe
pid1 := ErrorLevel
If (!pid1)
{  Process, Exist, ahkscript.exe
   pid2 := ErrorLevel
   If (pid2)
      Process, Close, %pid2%
   ExitApp
}
Return 
Last edited by eric04h on 26 Jul 2018, 14:47, edited 1 time in total.
Guest

Re: Run .bat on exit

25 Jul 2018, 16:10

bump. Really hoping to get this done but can't find any info on doing this and don't know much about scripting from scratch.
eric04h
Posts: 3
Joined: 25 Jul 2018, 02:26

Re: Run .bat on exit

26 Jul 2018, 14:48

Someone? Or can someone at least point me in the right direction on how to get started on this?
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: Run .bat on exit

26 Jul 2018, 15:10

Maybe I am missing something, but can't you just use

Code: Select all

 #NoEnv
#SingleInstance, Force
#Persistent
SetTitleMatchMode, 2
DetectHiddenWindows, On
 
SetTimer, ProcessCheckTimer, 3000
Return
 
ProcessCheckTimer:
Process, Exist, application1.exe
pid1 := ErrorLevel
If (!pid1)
{  Process, Exist, ahkscript.exe
   pid2 := ErrorLevel
   If (pid2)
      Process, Close, %pid2%
   Run, disabledriver.bat ;may need to give it the full path
   ExitApp
}
Return
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Run .bat on exit

26 Jul 2018, 15:11

Code: Select all

#NoEnv
#SingleInstance, Force
#Persistent
SetTitleMatchMode, 2
DetectHiddenWindows, On
 
SetTimer, ProcessCheckTimer, 3000
Return
 
ProcessCheckTimer:
Process, Exist, application1.exe
pid1 := ErrorLevel
If (!pid1)
{
	Process, Exist, ahkscript.exe
	pid2 := ErrorLevel
	If (pid2)
		Process, Close, %pid2%
	Run, Disabledriver.bat ; <-- Add this line
	ExitApp
}
Return
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Guest

Re: Run .bat on exit

26 Jul 2018, 15:36

the solution is literally hidden in the topic's title. USE ONEXIT
for example...

Onexit(ExitFunction)

ExitFunction(,)
{
run, C:\yourbatfilehere.bat
Guest

Re: Run .bat on exit

26 Jul 2018, 16:04

Thank you both very much! I'll have to dig into how to use Ahk more as its proved to be A very useful tool.

Since this code will be loaded into ahkscript.exe, Does the disabledriver.bat need to be in the code first before it executes exit ahkscript.exe or does it not matter?
eric04h
Posts: 3
Joined: 25 Jul 2018, 02:26

Re: Run .bat on exit

26 Jul 2018, 16:08

Thank you both very much! I'll have to dig into how to use Ahk more as its proved to be A very useful tool.

Since this code will be loaded into ahkscript.exe, Does the disabledriver.bat need to be in the code first before it executes exit ahkscript.exe or does it not matter? Not sure if this order would kill the script before it gets to run disabledriver

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], OrangeCat, scriptor2016 and 121 guests