Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Close A when B starts, then open A when B closes
New Posts  All Forums:Forum Nav:

Close A when B starts, then open A when B closes

post #1 of 5
Thread Starter 
So I am wondering how I would close an application (afterburner) automatically when another application starts (BF2). After, when BF2 is closed, I would want Afterburner to restart again.

I have no idea how this would be accomplished. The reason I want to do this is because punkbuster (for BF2) seems to think Afterburner is a hack and kicks me. I want to run Afterburner so that my overclock is applied at startup.

Thanks
Haswell
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 4670k Gigabyte UD3H EVGA GTX 770 SC Mushkin DDR3 2x8GB DDR3 1600 
Hard DriveCoolingOSMonitor
Samsung 830 256GB Thermalright Ultra 120 eXtreme Windows 7 x64 Dell U2312HM 
KeyboardPowerCaseMouse
Maxkeyboard Nighthawk X8 XFX P1-750B-BEFX 750W full modular Antec Twelve Hundred Razer Lachesis 
Audio
ASUS Xonar DX + ATH-M50S 
  hide details  
Reply
Haswell
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 4670k Gigabyte UD3H EVGA GTX 770 SC Mushkin DDR3 2x8GB DDR3 1600 
Hard DriveCoolingOSMonitor
Samsung 830 256GB Thermalright Ultra 120 eXtreme Windows 7 x64 Dell U2312HM 
KeyboardPowerCaseMouse
Maxkeyboard Nighthawk X8 XFX P1-750B-BEFX 750W full modular Antec Twelve Hundred Razer Lachesis 
Audio
ASUS Xonar DX + ATH-M50S 
  hide details  
Reply
post #2 of 5
An AutoIt script will accomplish what you need here. Here is the framework of it, you can compile it yourself or I can do it for you and attach it. I need to know the location of your bf2 executable file though, and make sure of the executable names for afterburner and bf2. Basically I need to know the exact name of the executables. Here is the code example:

Code:
$i = 0
Do
If Not ProcessExists("bf2.exe") Then
If Not ProcessExists("afterburner.exe") Then
Run ("C:\\wherever the folder is\\bf2.exe")
EndIf
EndIf
If ProcessExists("bf2.exe") Then
If ProcessExists("afterburner.exe") Then
ProcessClose("afterburner.exe")
EndIf
EndIf
Sleep(5000)
Until $i = 10
And here is the explanation:

The $i = 0 declares i as 0. More on this later.
Do... Until means to do this sequence of events until so and so.

If Not ProcessExists checks if bf2.exe is not running. If it is not, it checks to see if afterburner not running. If it is not it starts afterburner.

If ProcessExists checks if bf2.exe is running. If it is, then it checks if afterburner is running. If it is, then it closes afterburner. If not, nothing happens.

Sleep(5000) will stop this from looping at an infinite pace, eating up CPU cycles. It only checks every 5 seconds (5000 milliseconds), but can be done more or less often depending on your needs. The less often, the less CPU usage but this won't require tons of it anyway.

Until $i = 10 is the end of the Do statement. It will do this sequence over and over again until i = 10. Since i was declared as 0 in the beginning, it will loop infinitely. An executable .exe can be compiled and set to run during startup, which will keep this automated.

You will need to confirm the location of your executable though, and the names of afterburner and bf2.
Edited by LemonSlice - 12/25/10 at 8:05pm
Tiny Fun
(8 items)
 
4P Folding Rig 1
(16 items)
 
4P Folding Rig 2
(11 items)
 
CPUMotherboardGraphicsRAM
i7-4770K @ 4.0GHz MSI Z87I EVGA GTX 660 Ti Corsair Vengeance 16GB 
Hard DriveCoolingOSCase
Samsung 840 Pro 256GB Swiftech Apogee Drive II Windows 8 Enterprise x64 Cooler Master Elite 120 Advanced 
CPUCPUCPUCPU
AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core 
MotherboardGraphicsRAMHard Drive
SuperMicro H8QGi+-F Matrox G200eW 16x2 (32GB) Crucial Ballistix DDR3 1600MHz Crucial C300 64GB 
OSPowerCase
Linux Mint 15 Cinnamon 64-bit Enermax Galaxy Evo 1250W Spotswood Tech Tray 
CPUCPUCPUCPU
AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz 
MotherboardGraphicsRAMHard Drive
Supermicro H8QGL-IF+ Matrox G200eW Kingston Server 16x1GB DDR3 Corsair Nova 32GB 
OSPower
Linux Mint 15 Cinnamon 64-bit Cooler Master Silent Pro 1000W 
  hide details  
Reply
Tiny Fun
(8 items)
 
4P Folding Rig 1
(16 items)
 
4P Folding Rig 2
(11 items)
 
CPUMotherboardGraphicsRAM
i7-4770K @ 4.0GHz MSI Z87I EVGA GTX 660 Ti Corsair Vengeance 16GB 
Hard DriveCoolingOSCase
Samsung 840 Pro 256GB Swiftech Apogee Drive II Windows 8 Enterprise x64 Cooler Master Elite 120 Advanced 
CPUCPUCPUCPU
AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core 
MotherboardGraphicsRAMHard Drive
SuperMicro H8QGi+-F Matrox G200eW 16x2 (32GB) Crucial Ballistix DDR3 1600MHz Crucial C300 64GB 
OSPowerCase
Linux Mint 15 Cinnamon 64-bit Enermax Galaxy Evo 1250W Spotswood Tech Tray 
CPUCPUCPUCPU
AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz 
MotherboardGraphicsRAMHard Drive
Supermicro H8QGL-IF+ Matrox G200eW Kingston Server 16x1GB DDR3 Corsair Nova 32GB 
OSPower
Linux Mint 15 Cinnamon 64-bit Cooler Master Silent Pro 1000W 
  hide details  
Reply
post #3 of 5
Thread Starter 
Quote:
Originally Posted by LemonSlice View Post
An AutoIt script will accomplish what you need here. Here is the framework of it, you can compile it yourself or I can do it for you and attach it. I need to know the location of your bf2 executable file though, and make sure of the executable names for afterburner and bf2. Basically I need to know the exact name of the executables. Here is the code example:

Code:
$i = 0
Do
If Not ProcessExists("bf2.exe") Then
If Not ProcessExists("afterburner.exe") Then
Run ("C:\\wherever the folder is\\bf2.exe")
EndIf
EndIf
If ProcessExists("bf2.exe") Then
If ProcessExists("afterburner.exe") Then
ProcessClose("afterburner.exe")
EndIf
EndIf
Sleep(5000)
Until $i = 10
And here is the explanation:

The $i = 0 declares i as 0. More on this later.
Do... Until means to do this sequence of events until so and so.

If Not ProcessExists checks if bf2.exe is not running. If it is not, it checks to see if afterburner not running. If it is not it starts afterburner.

If ProcessExists checks if bf2.exe is running. If it is, then it checks if afterburner is running. If it is, then it closes afterburner. If not, nothing happens.

Sleep(5000) will stop this from looping at an infinite pace, eating up CPU cycles. It only checks every 5 seconds (5000 milliseconds), but can be done more or less often depending on your needs. The less often, the less CPU usage but this won't require tons of it anyway.

Until $i = 10 is the end of the Do statement. It will do this sequence over and over again until i = 10. Since i was declared as 0 in the beginning, it will loop infinitely. An executable .exe can be compiled and set to run during startup, which will keep this automated.

You will need to confirm the location of your executable though, and the names of afterburner and bf2.
S:\\Program Files (x86)\\MSI Afterburner\\MSIAfterburner.exe

G:\\Program Files (x86)\\EA Games\\Battlefield 2\\mods\\pr\\pr.exe

Code:
$i = 0
Do
If Not ProcessExists("bf2.exe") Then
If Not ProcessExists("MSIAfterburner.exe") Then
Run ("S:\\Program Files (x86)\\MSI Afterburner\\MSIAfterburner.exe")
EndIf
EndIf
If ProcessExists("bf2.exe") Then
If ProcessExists("MSIAfterburner.exe") Then
ProcessClose("MSIAfterburner.exe")
EndIf
EndIf
Sleep(5000)
Until $i = 10
This is what I did, it seems to work perfectly. I substituted the execution of Bf2.exe to afterburner as I knew what you intended there. I was able to compile it.

Thanks for the help!

Considering how simple this seems, is there a good place to go other than these forums for learning more about AutoIt?
Haswell
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 4670k Gigabyte UD3H EVGA GTX 770 SC Mushkin DDR3 2x8GB DDR3 1600 
Hard DriveCoolingOSMonitor
Samsung 830 256GB Thermalright Ultra 120 eXtreme Windows 7 x64 Dell U2312HM 
KeyboardPowerCaseMouse
Maxkeyboard Nighthawk X8 XFX P1-750B-BEFX 750W full modular Antec Twelve Hundred Razer Lachesis 
Audio
ASUS Xonar DX + ATH-M50S 
  hide details  
Reply
Haswell
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 4670k Gigabyte UD3H EVGA GTX 770 SC Mushkin DDR3 2x8GB DDR3 1600 
Hard DriveCoolingOSMonitor
Samsung 830 256GB Thermalright Ultra 120 eXtreme Windows 7 x64 Dell U2312HM 
KeyboardPowerCaseMouse
Maxkeyboard Nighthawk X8 XFX P1-750B-BEFX 750W full modular Antec Twelve Hundred Razer Lachesis 
Audio
ASUS Xonar DX + ATH-M50S 
  hide details  
Reply
post #4 of 5
I'm not sure about another place to learn about AutoIt, but perhaps these forums are good if you have specific questions. Also is the executable pl.exe or bf2.exe? If it's pl.exe you will need to update the script, but make sure it is the application that is running. For example, sometimes the launcher program isn't the game itself and quits after launch.
Tiny Fun
(8 items)
 
4P Folding Rig 1
(16 items)
 
4P Folding Rig 2
(11 items)
 
CPUMotherboardGraphicsRAM
i7-4770K @ 4.0GHz MSI Z87I EVGA GTX 660 Ti Corsair Vengeance 16GB 
Hard DriveCoolingOSCase
Samsung 840 Pro 256GB Swiftech Apogee Drive II Windows 8 Enterprise x64 Cooler Master Elite 120 Advanced 
CPUCPUCPUCPU
AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core 
MotherboardGraphicsRAMHard Drive
SuperMicro H8QGi+-F Matrox G200eW 16x2 (32GB) Crucial Ballistix DDR3 1600MHz Crucial C300 64GB 
OSPowerCase
Linux Mint 15 Cinnamon 64-bit Enermax Galaxy Evo 1250W Spotswood Tech Tray 
CPUCPUCPUCPU
AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz 
MotherboardGraphicsRAMHard Drive
Supermicro H8QGL-IF+ Matrox G200eW Kingston Server 16x1GB DDR3 Corsair Nova 32GB 
OSPower
Linux Mint 15 Cinnamon 64-bit Cooler Master Silent Pro 1000W 
  hide details  
Reply
Tiny Fun
(8 items)
 
4P Folding Rig 1
(16 items)
 
4P Folding Rig 2
(11 items)
 
CPUMotherboardGraphicsRAM
i7-4770K @ 4.0GHz MSI Z87I EVGA GTX 660 Ti Corsair Vengeance 16GB 
Hard DriveCoolingOSCase
Samsung 840 Pro 256GB Swiftech Apogee Drive II Windows 8 Enterprise x64 Cooler Master Elite 120 Advanced 
CPUCPUCPUCPU
AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core 
MotherboardGraphicsRAMHard Drive
SuperMicro H8QGi+-F Matrox G200eW 16x2 (32GB) Crucial Ballistix DDR3 1600MHz Crucial C300 64GB 
OSPowerCase
Linux Mint 15 Cinnamon 64-bit Enermax Galaxy Evo 1250W Spotswood Tech Tray 
CPUCPUCPUCPU
AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz 
MotherboardGraphicsRAMHard Drive
Supermicro H8QGL-IF+ Matrox G200eW Kingston Server 16x1GB DDR3 Corsair Nova 32GB 
OSPower
Linux Mint 15 Cinnamon 64-bit Cooler Master Silent Pro 1000W 
  hide details  
Reply
post #5 of 5
Thread Starter 
Quote:
Originally Posted by LemonSlice View Post
I'm not sure about another place to learn about AutoIt, but perhaps these forums are good if you have specific questions. Also is the executable pl.exe or bf2.exe? If it's pl.exe you will need to update the script, but make sure it is the application that is running. For example, sometimes the launcher program isn't the game itself and quits after launch.
pr.exe is the launcher. It tells bf2.exe to launch into the mod rather than the vanilla game. bf2.exe is the correct executable.

Thanks again!
Haswell
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 4670k Gigabyte UD3H EVGA GTX 770 SC Mushkin DDR3 2x8GB DDR3 1600 
Hard DriveCoolingOSMonitor
Samsung 830 256GB Thermalright Ultra 120 eXtreme Windows 7 x64 Dell U2312HM 
KeyboardPowerCaseMouse
Maxkeyboard Nighthawk X8 XFX P1-750B-BEFX 750W full modular Antec Twelve Hundred Razer Lachesis 
Audio
ASUS Xonar DX + ATH-M50S 
  hide details  
Reply
Haswell
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 4670k Gigabyte UD3H EVGA GTX 770 SC Mushkin DDR3 2x8GB DDR3 1600 
Hard DriveCoolingOSMonitor
Samsung 830 256GB Thermalright Ultra 120 eXtreme Windows 7 x64 Dell U2312HM 
KeyboardPowerCaseMouse
Maxkeyboard Nighthawk X8 XFX P1-750B-BEFX 750W full modular Antec Twelve Hundred Razer Lachesis 
Audio
ASUS Xonar DX + ATH-M50S 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Close A when B starts, then open A when B closes