Jump to content

Compiled AutoIt script paused for no apparent reason?


Recommended Posts

Hello, this is my first time on the forums. I hope this is the right place to post for assistance.

I've come across a script that would help me automate the closing/re-opening of a program based on the state of another program. (if program x is open, program y should be closed, and if program x is closed, program y can be open, where program x is any program from a list. When I use the SciTE-Lite editor to test the code (Tools > Go), the script works as intended. However, when I compile the script to place in my startup programs folder, the script does not work, entering a paused state instead (where the system tray icon flashes between the icon and a red x)

I'm not sure why this is happening so I'd appreciate some assistance. The script I'm using is attached (and also appended inline). (turn_rainmeter_off_when_gaming.au3) The script reads from a text file which contains a list of executables which I want the script to monitor (program x from the earlier example). The .txt is placed in the root of the C: drive but you can modify the script to place it anywhere you'd like.

Thanks in advance.

Script code in-line:

#include <Array.au3>
#include <File.au3>

Local $aGames
$file = "C:\Games.exe.txt"
_FileReadToArray($file, $aGames)

Local $sRunning

AdlibRegister("_CheckGame", 1000)
ConsoleWrite("_CheckGame() was registered by Adlib" & @CRLF)

While 1
        Sleep(100)
WEnd

Func _CheckGame()
        ; Assign a static variable to hold the number of times games are checked for.
        Local Static $iGameCount = 0
        Local Static $iCount = 0

        While 1
                For $i = 1 to UBound($aGames) -1
                        $iGameCount += 1
                        If $iGameCount > UBound($aGames) Then
                                $iGameCount = 0
                                $iCount += 1
                                ConsoleWrite("Checked for a game " & $iCount & " time(s)" & @CRLF)
                        EndIf

                        If ProcessExists($aGames[$i]) Then
                                $sRunning = FileReadLine($file, $i)
                                ConsoleWrite($sRunning & " was launched. Terminating Rainmeter." & @CRLF)
                                ProcessClose("Rainmeter.exe")
                                ConsoleWrite("Rainmeter has been terminated." & @CRLF)
                                ExitLoop 2
                        EndIf
                        Sleep(100)
                Next
        WEnd
        ConsoleWrite("Running game is " & $sRunning & @CRLF)
        ConsoleWrite("Checking if Rainmeter can be restarted..." & @CRLF)
        While 1
                If Not ProcessExists($sRunning) Then
                        ConsoleWrite("Starting Rainmeter..." & @CRLF)
                        ShellExecute("C:\Program Files\Rainmeter\Rainmeter.exe")
                        WinWait("Rainmeter")
                        ConsoleWrite("Rainmeter has been restarted." & @CRLF)
                        ExitLoop
                EndIf
        WEnd
        AdlibUnRegister("_CheckGame")
        AdlibRegister("_CheckGame")
EndFunc

Exit

 

turn_rainmeter_off_when_gaming.au3

Games.exe.txt

Link to comment
Share on other sites

  • Moderators

Hi,

This thread was reported as "game-related". As it merely checks whether certain processes are running and does not interact with the listed games in any way, I am happy for it to remain open.

dryshirt,

Welcome to the AutoIt forum.

As I said above, there is nothing wrong with this particular question, but please do read  the Forum rules so that you are aware of what is not permitted to be discussed here.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...