Overclock.net › Forums › Software, Programming and Coding › Other Software › [Solved] Looking for software that starts a program when one ends
New Posts  All Forums:Forum Nav:

[Solved] Looking for software that starts a program when one ends

post #1 of 8
Thread Starter 
Title basically explains it all, but here's why:

I like and use the program autohotkey for keyboard shortcuts to programs I use regularly. However, in the past couple of months PunkBuster has started kicking me for it when I play BF3 so I decided to stop using it, but I really do miss it.

I know I can make a .bat file to kill autohotkey and then launch BF3, but I would like autohotkey to launch automatically once I quit BF3 (when the bf3.exe process dissapears)

Any suggestions? I'm sure once I do find a program to do this, I can find other uses for it as well.

EDIT: Finally came up with a solution. Thanks guys.
Code:
@echo off

TASKKILL /im Autohotkey*

START "BF3" "G:\Program Files (x86)\Electronic Arts\Battlefield 3\bf3.exe"

echo Give BF3.exe time to start Origin and Browser and then quit itself.
timeout 15

:isOriginRunning
tasklist /nh /FI "Imagename eq Origin.exe" 2>NUL | find /I /N "Origin.exe">NUL
if "%ERRORLEVEL%"=="1" goto OriginHasStopped

echo Origin is running. You are probably just taking a break or choosing a server.
goto :WaitForBF3toStart

:WaitForBF3toStart
timeout 3
tasklist /nh /FI "Imagename eq bf3.exe" 2>NUL | find /I /N "bf3.exe">NUL
if "%ERRORLEVEL%"=="1" goto isOriginRunning

:BF3HasStarted
timeout 3
tasklist /nh /FI "Imagename eq bf3.exe" 2>NUL | find /I /N "bf3.exe">NUL
if "%ERRORLEVEL%"=="1" goto BF3HasStopped
echo BF3 is running.
goto BF3HasStarted

:BF3HasStopped
echo BF3 is not running anymore. Checking if Origin is still running...
goto isOriginRunning

:OriginHasStopped
echo You are probably done playing BF3 for now. Launching AutoHotkey now.
START "AHK" "C:\Program Files (x86)\AutoHotkey\AutoHotkey.exe"
TASKKILL /f /im iexplore.exe
goto END
:END

Edited by Evermind - 7/19/12 at 6:52pm
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 D0 @ 4ghz EVGA X58 SLI3 SLI MSI GTX 580 XL 3GB 12GB Gskill Ripjaw DDR3 1600 
Hard DriveOSPowerCase
Crucial 120GB SSD / 2x WD6401AALS / 1x WD20EARS Windows 7 x64 Pro Corsair HX1050 Coolermaster HAF932 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 D0 @ 4ghz EVGA X58 SLI3 SLI MSI GTX 580 XL 3GB 12GB Gskill Ripjaw DDR3 1600 
Hard DriveOSPowerCase
Crucial 120GB SSD / 2x WD6401AALS / 1x WD20EARS Windows 7 x64 Pro Corsair HX1050 Coolermaster HAF932 
  hide details  
Reply
post #2 of 8
Could just take advantage of the /wait argument with start in a batch file.

Edit: See here thumb.gif
post #3 of 8
Thread Starter 
Excellent suggestion, but I got stuck here.
Code:
TASKKILL /IM AutoHotkey*

START "BF3" /wait /b "G:\Program Files (x86)\Electronic Arts\Battlefield 3\bf3.exe"

REM c:

REM cd \Program Files (x86)\AutoHotkey\

REM AutoHotKey.exe

The wait happens so quick because bf3.exe doesn't persist on intial run, it launches Origin and then the Web interface for Multiplayer and then exits. bf3.exe doesn't pop up again until you join a game from the web interface.

Trying to think of workarounds, but can't - it's almost like I need a program that constantly monitors for bf3.exe
Edited by Evermind - 7/15/12 at 3:59pm
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 D0 @ 4ghz EVGA X58 SLI3 SLI MSI GTX 580 XL 3GB 12GB Gskill Ripjaw DDR3 1600 
Hard DriveOSPowerCase
Crucial 120GB SSD / 2x WD6401AALS / 1x WD20EARS Windows 7 x64 Pro Corsair HX1050 Coolermaster HAF932 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 D0 @ 4ghz EVGA X58 SLI3 SLI MSI GTX 580 XL 3GB 12GB Gskill Ripjaw DDR3 1600 
Hard DriveOSPowerCase
Crucial 120GB SSD / 2x WD6401AALS / 1x WD20EARS Windows 7 x64 Pro Corsair HX1050 Coolermaster HAF932 
  hide details  
Reply
post #4 of 8
How about a grep check and if with goto :top and slight pause else start.

tasklist /FI "bf3.exe" 2>NUL | find /I /N "bf3.exe">NUL
if "%ERRORLEVEL%"=="0"
Edited by Dishastur - 7/15/12 at 4:21pm
post #5 of 8
Thread Starter 
This is my attempt, but honestly I don't know what that command is trying to do. Can you put it into English for me?
Code:
TASKKILL /im AutoHotkey*

START "BF3" /wait /b "G:\Program Files (x86)\Electronic Arts\Battlefield 3\bf3.exe"

timeout 30
:RepeatMe
tasklist /FI "bf3.exe" 2>NUL | find /I /N "bf3.exe">NUL
if "%ERRORLEVEL%"=="0"
GOTO RepeatMe


START "AHK" "C:\Program Files (x86)\AutoHotkey\AutoHotKey.exe"

TASKKILL /f /im Origin*

TASKKILL /im iexplore*

EDIT: Guess I'll just go with this for now. Pauses after it lanches BF3 so when I quit BF3 I can just press the any key and it will kill IE9, Origin, and restart AutoHotkey for me.
Code:
TASKKILL /f /im AutoHotkey*

START "BF3" /wait /b "G:\Program Files (x86)\Electronic Arts\Battlefield 3\bf3.exe"

pause

START "AHK" "C:\Program Files (x86)\AutoHotkey\AutoHotKey.exe"

TASKKILL /f /im Origin*

TASKKILL /f /im iexplore*

Edited by Evermind - 7/15/12 at 5:55pm
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 D0 @ 4ghz EVGA X58 SLI3 SLI MSI GTX 580 XL 3GB 12GB Gskill Ripjaw DDR3 1600 
Hard DriveOSPowerCase
Crucial 120GB SSD / 2x WD6401AALS / 1x WD20EARS Windows 7 x64 Pro Corsair HX1050 Coolermaster HAF932 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 D0 @ 4ghz EVGA X58 SLI3 SLI MSI GTX 580 XL 3GB 12GB Gskill Ripjaw DDR3 1600 
Hard DriveOSPowerCase
Crucial 120GB SSD / 2x WD6401AALS / 1x WD20EARS Windows 7 x64 Pro Corsair HX1050 Coolermaster HAF932 
  hide details  
Reply
post #6 of 8
Sorry about that, I'm away from Windows atm so I didn't want to write a complete script without being able to test it. Hoped that the SS64 doc would provide the information you needed.

The first line lists the processes currently running which is then fed to grep to check for BF3 or whatever. Next the if command does one thing if the application is running or else it does another thing. So for example it could either goto :recheck with sleep or launch AHK. In this case you'd need to also check for Origin with same approach.
Edited by Dishastur - 7/19/12 at 8:18pm
post #7 of 8
You might be able to also combine the batch files with Task Scheduler to make it work the way you want it to, so it is more 'automated' for you.
    
CPUMotherboardGraphicsRAM
INTEL ASUS XFX & SAPPHIRE SAMSUNG 
Hard DriveOptical DriveOSMonitor
WD/ST LG WINDOWS LG/SAMSUNG 
KeyboardPowerCaseMouse
IBM CORSAIR THERMALTAKE LOGITECH 
Mouse PadAudio
ROCKETFISH ONBOARD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
INTEL ASUS XFX & SAPPHIRE SAMSUNG 
Hard DriveOptical DriveOSMonitor
WD/ST LG WINDOWS LG/SAMSUNG 
KeyboardPowerCaseMouse
IBM CORSAIR THERMALTAKE LOGITECH 
Mouse PadAudio
ROCKETFISH ONBOARD 
  hide details  
Reply
post #8 of 8
Thread Starter 
Finally got it. Also added to OP.
Maybe someone else will find it useful or adapt it for another use.
Code:
@echo off

TASKKILL /im Autohotkey*

START "BF3" "G:\Program Files (x86)\Electronic Arts\Battlefield 3\bf3.exe"

echo Give BF3.exe time to start Origin and Browser and then quit itself.
timeout 15

:isOriginRunning
tasklist /nh /FI "Imagename eq Origin.exe" 2>NUL | find /I /N "Origin.exe">NUL
if "%ERRORLEVEL%"=="1" goto OriginHasStopped

echo Origin is running. You are probably just taking a break or choosing a server.
goto :WaitForBF3toStart

:WaitForBF3toStart
timeout 3
tasklist /nh /FI "Imagename eq bf3.exe" 2>NUL | find /I /N "bf3.exe">NUL
if "%ERRORLEVEL%"=="1" goto isOriginRunning

:BF3HasStarted
timeout 3
tasklist /nh /FI "Imagename eq bf3.exe" 2>NUL | find /I /N "bf3.exe">NUL
if "%ERRORLEVEL%"=="1" goto BF3HasStopped
echo BF3 is running.
goto BF3HasStarted

:BF3HasStopped
echo BF3 is not running anymore. Checking if Origin is still running...
goto isOriginRunning

:OriginHasStopped
echo You are probably done playing BF3 for now. Launching AutoHotkey now.
START "AHK" "C:\Program Files (x86)\AutoHotkey\AutoHotkey.exe"
TASKKILL /f /im iexplore.exe
goto END
:END

Edited by Evermind - 7/19/12 at 6:51pm
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 D0 @ 4ghz EVGA X58 SLI3 SLI MSI GTX 580 XL 3GB 12GB Gskill Ripjaw DDR3 1600 
Hard DriveOSPowerCase
Crucial 120GB SSD / 2x WD6401AALS / 1x WD20EARS Windows 7 x64 Pro Corsair HX1050 Coolermaster HAF932 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 D0 @ 4ghz EVGA X58 SLI3 SLI MSI GTX 580 XL 3GB 12GB Gskill Ripjaw DDR3 1600 
Hard DriveOSPowerCase
Crucial 120GB SSD / 2x WD6401AALS / 1x WD20EARS Windows 7 x64 Pro Corsair HX1050 Coolermaster HAF932 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Other Software
Overclock.net › Forums › Software, Programming and Coding › Other Software › [Solved] Looking for software that starts a program when one ends