Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thaddeusc1/fea3e0a703d0c3c77f8d25f4ead8e09d to your computer and use it in GitHub Desktop.
Save thaddeusc1/fea3e0a703d0c3c77f8d25f4ead8e09d to your computer and use it in GitHub Desktop.
Enforce single WD Dashboard instance
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# https://learn.microsoft.com/en-us/shows/inside/hresult
$HRESULT_S_OK= 0x0 # Operation successful
$HRESULT_S_FALSE= 0x1 # Operation successful but returned no results
$HRESULT_E_ABORT= 0x80004004 # Operation aborted
$HRESULT_E_FAIL= 0x80004005 # Unspecified failure
$HRESULT_E_UNEXPECTED= 0x8000FFFF # Unexpected failure
$HRESULT_E_ACCESSDENIED=0x80070005 # General access denied error
$HRESULT_E_INVALIDARG= 0x80070057 # One or more arguments are not valid
$hResult=$HRESULT_E_ABORT
<# System.Diagnostics.Process #> $runningDashboards = Get-Process -Name "Dashboard"
try
{
Stop-Process -InputObject $runningDashboards[1,$runningDashboards.Length] -ErrorAction Stop
$hResult=$HRESULT_S_OK
}
catch [System.Management.Automation.ParameterBindingException]
{
if( $_.Exception.Message.Contains("empty array") `
-bOR $_.Exception.Message.Contains("it is null") )
{
# Stopping duplicate processes was successful because no duplicates were running.
$hResult=$HRESULT_S_FALSE
}
else
{
$hResult=$HRESULT_E_INVALIDARG
}
}
catch [System.SystemException]
{
if( $_.Exception.Message.Contains("Access is denied") )
{
$hResult=$HRESULT_E_ACCESSDENIED
}
else
{
$hResult=$HRESULT_E_FAIL
}
}
catch
{
$hResult=$HRESULT_E_UNEXPECTED
}
exit $hResult
@thaddeusc1
Copy link
Author

thaddeusc1 commented May 13, 2023

Quit duplicate WD Dashboard instances that are launched at log-on.

The WD Dashboard background task will start multiple times iff I have more than one (1) Western Digital SSD installed in my PC—even though a single instance of the WD Dashboard manages all Western Digital storage devices connected to my PC. I wrote this script to automate the process of exiting duplicate WD Dashboard processes.

Configure Windows Task Scheduler

This script is meant to be automatically triggered after logging-in to Windows.

Recommended task properties

  • General
    • Security options
      • "Run only when user is logged on"
        • Assumption 💡: the "user" that is logging-on has admin privileges.
      • Run with highest privileges: ☑️ (enabled)
  • Triggers
    • Trigger: At log on
      • Delay task for: 3 minutes
  • Actions
    • Action: Start a program
      • Details
        • Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
        • Add Agruments: -NonInteractive -NoLogo -NoProfile -File quit-duplicate-wd-dashboard-processes.ps1
        • Start in: </path/to/where/you/downloaded/the/script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment