Sonarr version 4.0.16.2944: OS: Windows 11 25h2 Debug logs: N/A Description of issue:
I’m using Sonarr on this machine in tray mode and I expect the background executable to stop running when I exit the tray icon, but it continues to run in the background.
While I want it to shut down the process when the tray icon is exited, the secondary issue is that, if I do close the tray icon and not kill the process, when I start the application again, the tray icon will not connect to the existing process - so, I have to kill the process when I exit, regardless.
First and foremost, I prefer the process shut down when I exit.
Apologies if this was posted somewhere. I hadn’t any luck finding a result though the search feature.
Not having received a response, I took care of it myself.
If anyone wants the monitarr commandline script for windows:
Create new file “monitarr.cmd” somewhere of your choice and add it to your Startup folder by creating a shortcut to the file and put the shortcut in %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup and it will run when you boot. For security reasons, I won’t post a link, but rather the contents so you can review it and know it’s safe.
@echo off
echo monitarr will monitor sonarr’s system tray icon and close the sonarr.exe processes that runs when it should not run after exiting via tray icon.
setlocal enabledelayedexpansion
Run minimized in background
if not %1==minimized (
start min %~f0 minimized
exit b
)
monitor_loop
Check if Sonarr.exe process exists
tasklist FI IMAGENAME eq Sonarr.exe 2NUL find I N Sonarr.exeNUL
if %ERRORLEVEL% neq 0 (
Sonarr.exe not running, wait and check again
timeout t 5 nobreak NUL
goto monitor_loop
)
Sonarr is running - check for tray icon window
The tray icon is associated with a hidden window class
powershell -WindowStyle Hidden -Command Add-Type -TypeDefinition @'^
using System;
using System.Runtime.InteropServices;
public class WinAPI {
[DllImport(user32.dll, SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
}
'^; $window = [WinAPI]FindWindow(‘WindowsForms10.Window.8.app.0.141b42a_r6_ad1’, ‘Sonarr’); if ($window -eq [IntPtr]Zero) { exit 1 } else { exit 0 }
if %ERRORLEVEL% neq 0 (
Tray icon window not found - kill Sonarr
echo Sonarr tray icon closed. Killing Sonarr.exe…
taskkill F IM Sonarr.exe NUL 2&1
timeout t 10 nobreak NUL
)
Wait before checking again
timeout t 2 nobreak NUL
goto monitor_loop