Skip to content

Instantly share code, notes, and snippets.

@troubear
Last active January 18, 2024 07:10
Show Gist options
  • Save troubear/c746c4f5a9b5886f8c1c7f6f5f190f70 to your computer and use it in GitHub Desktop.
Save troubear/c746c4f5a9b5886f8c1c7f6f5f190f70 to your computer and use it in GitHub Desktop.
システムトレイアイコンの表示・非表示一覧に無限増殖するdgtrayicon.exeを一括削除するスクリプト
@echo off
pushd %~dp0
powershell -ExecutionPolicy Bypass -File ".\remove_dangling_dgtrayicons.ps1" %*
popd
pause
# 削除対象のレジストリキーの情報
$registryRoot = "Registry::HKEY_CURRENT_USER\Control Panel\NotifyIconSettings"
$subkeyPropertyName = "ExecutablePath"
$subkeyPropertyValue = "\dgtrayicon.exe"
function Delete-MatchingSubkeys {
param (
[string]$registryRoot,
[string]$subkeyPropertyName,
[string]$subkeyPropertyValue
)
try {
$subkeys = Get-Item -LiteralPath $registryRoot | Get-ChildItem | ForEach-Object { $_.PSChildName }
foreach ($subkey in $subkeys) {
$subkeyPath = Join-Path -Path $registryRoot -ChildPath $subkey
$value = (Get-ItemProperty -LiteralPath $subkeyPath -Name $subkeyPropertyName).$subkeyPropertyName
if ($value.EndsWith($subkeyPropertyValue)) {
Write-Host "Remove: $subkeyPath"
Remove-Item -LiteralPath $subkeyPath -Recurse -Force
}
}
}
catch {
Write-Host "Error: $_"
}
}
Delete-MatchingSubkeys -registryRoot $registryRoot -subkeyPropertyName $subkeyPropertyName -subkeyPropertyValue $subkeyPropertyValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment