Repository navigation
Expand file tree
/
Copy pathreorder-ShellIconOverlayIdentifiers.ps1
More file actions
65 lines (63 loc) · 2.59 KB
/
Copy pathreorder-ShellIconOverlayIdentifiers.ps1
File metadata and controls
65 lines (63 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function Process
{
$keyPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers'
$key = Get-Item -Path $keyPath
$subkeys = Get-ChildItem -Path $keyPath
$nameToNewName = @{}
$newNameAlreadyExist = @{}
foreach ($subkey in $subkeys)
{
$name = Split-Path -Path $subkey.Name -Leaf
$rawName = $name.Trim()
$level = 0
switch -Wildcard ($rawName)
{
{$_ -cmatch '^Tortoise\d'}
{ $level = 5; break }
{$_ -cmatch '^IconOverlay'}
{ $level = 4; break }
{$_ -cmatch '^AccExtIco\d'}
{ $level = 3; break }
}
$newName = (' ' * $level) + $rawName
$nameToNewName[$name] = $newName
if (-not $newNameAlreadyExist.ContainsKey($newName) -or
-not $newNameAlreadyExist[$newName])
{
# Set $newName existance flag
$newNameAlreadyExist[$newName] = ($name -ceq $newName);
}
}
foreach ($subkey in $subkeys)
{
$name = Split-Path -Path $subkey.Name -Leaf
$newName = $nameToNewName[$name]
# If $newName already exists
if ($newNameAlreadyExist[$newName])
{
# Remove if it is a redundant name
if ($name -cne $newName)
{
Remove-Item -Path "HKLM:$subkey"
}
}
else
{
# Rename the first $name to $newName
Rename-Item -Path "HKLM:$subkey" -NewName "$newName"
# Will remove redundant names
$newNameAlreadyExist[$newName] = $true
}
}
}
function Pause($M="Press any key to continue . . . "){if($psISE){$S=New-Object -ComObject "WScript.Shell";$B=$S.Popup("Click OK to continue.",0,"Script Paused",0);return};Write-Host -NoNewline $M;$I=16,17,18,20,91,92,93,144,145,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183;while($K.VirtualKeyCode -Eq $Null -Or $I -Contains $K.VirtualKeyCode){$K=$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")};Write-Host}
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
Process
if($psISE){(New-Object -ComObject 'WScript.Shell').Popup('Click OK to continue...',0,'Script done',0)}else{Write-Host 'Done. Press any key to continue...' -NoNewline;$key=$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").VirtualKeyCode}
}
else
{
Start-Process -FilePath 'powershell' -Verb RunAs -ArgumentList '-File', """$PSCommandPath"""
}