Last active
January 18, 2024 07:10
-
-
Save troubear/c746c4f5a9b5886f8c1c7f6f5f190f70 to your computer and use it in GitHub Desktop.
システムトレイアイコンの表示・非表示一覧に無限増殖するdgtrayicon.exeを一括削除するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
pushd %~dp0 | |
powershell -ExecutionPolicy Bypass -File ".\remove_dangling_dgtrayicons.ps1" %* | |
popd | |
pause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 削除対象のレジストリキーの情報 | |
$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