Automatically Close the Blue Iris Application after an Idle Time

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
I've developed an approach to automatically close the Blue Iris desktop application after the computer is idle for X minutes.
(I use X=30 minutes)

EDIT (1/26/2024): attached script updated to V3 (
changelog).

Key Point: The Blue Iris service is not terminated when the application is closed.

Using the approach requires the following:
1. [Optional] Editing a PowerShell script to configure your custom idle time. And Pushover settings if you want to receive notifications, like this
1673480539278.jpeg


2. Executing the PowerShell script every N minutes via Task Scheduler (I use 15 minutes).

Why would you want to use this utility?
1. to reduce the CPU load on the Blue Iris PC.
2. to avoid occasional BI application lock ups when left running unattended for extended periods of time.

======
Caveats

1. Running the PowerShell script from Task Scheduler will result in a flashing PowerShell window when the task runs. This appears to be unavoidable and I have found no work around. The flash is very brief, but you may find it annoying or distracting. I've gotten used to it.

2. After the PowerShell script force closes the Blue Iris application, the Blue Iris icon in the system tray may be "orphaned". Simply mousing over the orphaned icon will cause it go away if the application is not running.
1673541935286.png


======
Create/configure Task Scheduler task to run the PowerShell script

This topic is described in the comments at the top of the attached PowerShell script.
Code:
# HOW TO AUTOMATE THIS SCRIPT VIA TASK SCHEDULER
#   Open Task Scheduler and create an appropriately named task with one triggers and one action:
#   Task Scheduler
#   'General' tab
#        'Run only when user is logged in'  [REQUIRED] SEE NOTE #1
#        'Run with highest privileges'      [REQUIRED] SEE NOTE #2
#   'Triggers' tab:
#       'Daily' or 'One time' (e.g., at 12:05 AM, every 15 minutes)
#       (Note: I find 'One time' to be more reliable)
#   'Actions' tab:
#       Program/script: powershell.exe
#       Add arguments: {your_powershell_scripts_path)\{script_file_name}.ps1
#
# NOTES:
#   #1: This setting UNFORTUNATELY results in a flashing PowerShell window when the task runs.
#       While this issue can generally be avoided by running the task with setting:
#       General tab > 'Run whether user is logged in or not'
#        this is not a viable option b/c it causes this script to fail to acquire the desired idle time.
#       Therefore, we must use the specified setting.
#   #2: 'taskkill' requires administrative privileges to kill a task.
Tip#1: To make sure the Task Scheduler task is working...
1. Edit the PowerShell script starting at line 184 251 and uncomment the code using msg.exe.
2. Also opt in to sending Pushover notifications.
3. Right-click the task, and select 'Run'.
Note: Once you've confirmed that the task is working, don't forget to return the script to it initial condition.

Tip#2: If you are getting spammed with Pushover notifications, you do not need to delete the task.
Rather, right-click the task and select 'Disable'. Then debug the task and/or script.

======
Using/Testing the PowerShell Script

To experiment with this script, simply
1. Extract the BI_app_stop_if_idle.ps1 file from the attached zip file to your desktop, or scripts folder.
2. Run the script from a Admin PowerShell window.
The script can also be executed from an Admin cmd.exe window using a command like powershell.exe "C:\ps_scripts\BI_app_stop_if_idle.ps1"

NOTE: If you've never used PowerShell on your Blue Iris PC, you may first to need to change its default security policy.
Open PowerShell in Administrator mode, and type the following, then hit the Enter key Set-ExecutionPolicy RemoteSigned
(click <here> for a nice beginner's tutorial to using PowerShell).

The following screenshots illustrate the script's output (in a PowerShell window).

1. Usage in 'demo' mode.
demo_mode.png


2. Usage in normal mode.
normal_mode.png
 

Attachments

Last edited:

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
Utility updated to V2.
See the original post to download.

Changelog:
  1. IMPROVED: Tweaked handling of output from 'tasklist' command.
  2. IMPROVED: layout of USER SETTINGS section.
  3. CHANGE: Migrated code for notifications to functions (Pushover, and custom BI log entries).
 
Last edited:

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
Utility updated to V3.
See the original post to download.

Note the BREAKING CHANGE.

The main reason for this update is to support the termination of processes in addition to the Blue Iris application. These are processes that do not need to be running when you are no longer working with the computer.

WHY? - I've become increasingly suspicious that some high CPU usage spikes and memory leak events may be caused by processes other than Blue Iris (my leading suspect is the Chrome browser with its few dozen open tabs).

Changelog:
  1. BREAKING CHANGE: moved USER SETTINGS code section to separate script file '{scriptname}_user_settings.ps1'
  2. NEW: Added support for killing additional processes (see user_settings file)
  3. NEW: Added arguments -Demo, -NoBiLog, -NoPushover, -Help
  4. CHANGE: Consolidated duplicative code for closing app(s) to new function
 
Top