A script to relaunch your uTorrent automatically if it crashes
-
I was asked by a user if there was any way to configure uTorrent to relaunch automatically if it crashes. While I would prefer that the user not have crashes, and/or determine the cause of them and fix it, I can still see the use for a script of that sort.
I use a scripting tool called AutoIt for things like this. It's completely free, and it uses an easy to use scripting language that looks somewhat like BASIC. I put together a little script that does the following:
1. When first launched, it checks if the specified application is running, an if it is not found, it launches it.
2. It sits running in the background checking regularly that the app is still running. If it ever finds it missing, it will relaunch it.
3. It has three global hotkeys to enable and disable the checking (so you can temporarily turn off the auto-launch) and one to completely exit the script.
4. The default behaviour is to only attempt a launch at max once per 60 seconds. (This should prevent any bug from making a real mess.)As you are going to have the source code, you can freely modify it to suit your needs. You can change the hot keys, you can change the checking interval and you can change which app is monitored and launched.
NOTE You need to edit the script to tell it the correct location for your copy of uTorrent, as it is usually specific to the logged in user.
I have tested this script on Windows 8.1 and Windows 10 Technical Preview. If you use it on other versions of Windows, please feel free to add a note here in the forum to let us know how it worked for you.
There is no warranty of any kind, but I will try my best to help you if you run into problems, just leave a message at the beep
As the code says, You can get AutoIt v3 here: https://www.autoitscript.com/site/ or for the truly lazy https://www.autoitscript.com/site/autoit/downloads/
Enjoy,
NickHere's the code (and it's also attached, but the name is .txt instead of .au3 because the site prevents unknown file types.) Save the code as: Restart_uTorrent.au3
; This script was written by NMD for GayTorrent.ru ; ; It's an AutoIt script that monitors uTorrent and if ; it's not running, it restarts it. ; ; You can get AutoIt v3 here: ; [url]https://www.autoitscript.com/site/[/url] ; or for the truly lazy ;) [url]https://www.autoitscript.com/site/autoit/downloads/[/url] ; ; When the script is first launched it will immediately do a check and then ; launch uTorrent right then if necessary. It will then keep checking on a ; regular basis and relaunch it again if it goes missing (crashes.) ; ; There are some global variables you may want to tweak, such as how often ; the checks occur. Right now it will only relaunch it once every minute ; to prevent thinks from getting too out of hand should things go truly ; amiss. (You don't want to check too often in case the system gets ; bogged down and you get it trying to launch it multiple times.) ; ; You also will need to edit the path to your uTorrent executable, as ; it appears a default install might install it into a location that ; is user specific. ; ; The script has a couple of Global Hotkeys to enable and disable it so ; you can leave it running but disabled and then quickly start it up ; again later. It also has a Global Hotkey to completely shut it down ; and allow it to leave the system. ; ; The hotkeys are: ; SHIFT-ALT-1 Start Monitoring and re-launching ; SHIFT-ALT-2 Stop Monitoring ; SHIFT-ALT-3 Shut down the script completely ; ; Global $GlobalHotKey_Start = "+!1" ;Shift-Alt-1 Global $GlobalHotKey_Stop = "+!2" ;Shift-Alt-2 Global $GlobalHotKey_Exit = "+!3" ;Shift-Alt-3 ; Global $SecondsBetweenChecks = 60 Global $ProcessPath = "C:\Users\Nick\AppData\Roaming\uTorrent\uTorrent.exe" Global $ProcessName = "uTorrent.exe" ; Left these here to ease testing, as notepad is usually in a known location ; whereas uTorrent tends to be in a user specific location ;;;Global $ProcessPath = "C:\Windows\notepad.exe" ;;;Global $ProcessName = "notepad.exe" ; Global $CheckingEnabled = 0 Global $StillRunning = 1 Global $LastCheck = TimerInit() ; HotKeySet($GlobalHotKey_Start, "DoBegin") HotKeySet($GlobalHotKey_Stop, "DoEnd") HotKeySet($GlobalHotKey_Exit, "DoShutdown") ; ;;;; Body of program would go here ;;;; DoBegin() DoAlmostInfiniteLoop() DoEnd() DoExit() ;;;;;;;; Func DoBegin() $CheckingEnabled = 1 DoProcessCheck() EndFunc Func DoEnd() $CheckingEnabled = 0 EndFunc Func DoAlmostInfiniteLoop() While $StillRunning If $CheckingEnabled Then DoProcessCheckIfNotTooRecent() EndIf Sleep(1000) WEnd EndFunc Func DoShutdown() $StillRunning = 0 EndFunc Func DoExit() ; Remove all the global hotkeys HotKeySet($GlobalHotKey_Start) HotKeySet($GlobalHotKey_Stop) HotKeySet($GlobalHotKey_Exit) Exit EndFunc Func DoProcessCheckIfNotTooRecent() If TimerDiff($LastCheck) > ( $SecondsBetweenChecks * 1000 ) Then DoProcessCheck() EndIf EndFunc Func DoProcessCheck() If Not ProcessExists($ProcessName) Then Run($ProcessPath) ; if the process doesn't exist then start it $LastCheck = TimerInit() EndFunc ;;;;;;;;;;;;;;;;;;; End of script ;;;;;;;;;;;;;;;;;;; ```[Restart_uTorrent.txt](/uploads/_imported_attachments/migrated/81613_Restart_uTorrent.txt)
-
Hi, Nick!!! Thanks for this great script!
I'm just curious about one thing…
Since I haven't been one to suffer uTorrent crashing....
WHY (and how?) do members experience the problem of uTorrent "crashing" ???
I just wasn't aware this could be a common occurrence, and I'd enjoy knowing a bit more about this oddity.
I'm using 2.2.1 build 25302, btw
Thanks,
Pawpcorn -
Since I haven't been one to suffer uTorrent crashing….
WHY (and how?) do members experience the problem of uTorrent "crashing" ???
Actually Pawpcorn that's a good question. The user that requested a means to have uTorrent auto-restart said he had 800+ torrents in it, and thought that might have been part of the reason for it crashing. I gave him advice on cleaning it up (how to select and remove multiple torrents at once) but then I also thought the script was a kinda fun challenge for a a couple of hours (well not long to write, longer to test it properly
It could be used for any process that might exit unexpectedly… Or hell.. if you changed the checking interval to much longer, you could even use in unexpected ways, like to occasionally do a backup or something
Nick