echo "# Self-elevate the script unless already Administrator"
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
echo "# We are not admin, launching a new PowerShell as Administrator"
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
} else {
echo "# Disable Explorer AutoRestartShell"
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -Value 0 -Verbose
echo "# Killing Explorer Process"
Stop-Process -ProcessName explorer -Force -Verbose
echo "# Delete IconStreams Key"
Remove-ItemProperty -Path "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" -Name IconStreams -Force -Verbose
echo "# Delete PastIconsStream"
Remove-ItemProperty -Path "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" -Name PastIconsStream -Force -Verbose
echo "# Restore Explorer AutoRestartShell"
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -Value 1 -Verbose
echo "# Start Explorer Again"
Start-Process explorer.exe -LoadUserProfile -Verbose
echo "# Pause before exit to examine output"
pause
Exit
}