Advertisement
HashDio

Close apps when other apps are open

Jul 29th, 2019
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.09 KB | None | 0 0
  1. ; slight modification of u/Medallyonify's code to close rainmeter when games are open
  2.  
  3. #include <Array.au3>
  4. #include <File.au3>
  5.  
  6. Local $aGames
  7. $file = "C:\Games\Games.exe.txt"
  8. _FileReadToArray($file, $aGames)
  9.  
  10. Local $sRunning
  11.  
  12. AdlibRegister("_CheckGame", 1000)
  13. ConsoleWrite("_CheckGame() was registered by Adlib" & @CRLF)
  14.  
  15. While 1
  16.         Sleep(100)
  17. WEnd
  18.  
  19. Func _CheckGame()
  20.         ; Assign a static variable to hold the number of times games are checked for.
  21.         Local Static $iGameCount = 0
  22.         Local Static $iCount = 0
  23.  
  24.         While 1
  25.                 For $i = 1 to UBound($aGames) -1
  26.                         $iGameCount += 1
  27.                         If $iGameCount > UBound($aGames) Then
  28.                                 $iGameCount = 0
  29.                                 $iCount += 1
  30.                                 ConsoleWrite("Checked for a game " & $iCount & " time(s)" & @CRLF)
  31.                         EndIf
  32.  
  33.                         If ProcessExists($aGames[$i]) Then
  34.                                 $sRunning = FileReadLine($file, $i)
  35.                                 ConsoleWrite($sRunning & " was launched. Terminating Rainmeter." & @CRLF)
  36.                                 ProcessClose("Rainmeter.exe")
  37.                                 ConsoleWrite("Rainmeter has been terminated." & @CRLF)
  38.                                 ExitLoop 2
  39.                         EndIf
  40.                         Sleep(100)
  41.                 Next
  42.         WEnd
  43.         ConsoleWrite("Running game is " & $sRunning & @CRLF)
  44.         ConsoleWrite("Checking if Rainmeter can be restarted..." & @CRLF)
  45.         While 1
  46.                 If Not ProcessExists($sRunning) Then
  47.                         ConsoleWrite("Starting Rainmeter..." & @CRLF)
  48.                         ShellExecute("C:\Program Files\Rainmeter\Rainmeter.exe")
  49.                         WinWait("Rainmeter")
  50.                         ConsoleWrite("Rainmeter has been restarted." & @CRLF)
  51.                         ExitLoop
  52.                 EndIf
  53.         WEnd
  54.         AdlibUnRegister("_CheckGame")
  55.         AdlibRegister("_CheckGame")
  56. EndFunc
  57.  
  58. Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement