Last active
October 31, 2025 11:40
-
-
Save NickSlash/251e998ed63eb9c69dee23830731a11d to your computer and use it in GitHub Desktop.
Modify Icons on DefaultApplication
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
| $extension = ".htm" | |
| $icon = "%SystemRoot%\System32\ddores.dll,-210" | |
| $userChoice = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${extension}\UserChoice" | |
| try { | |
| if (Test-Path $userChoice) { | |
| $progId = (Get-ItemProperty -Path $userChoice -Name "ProgId" -ErrorAction Stop).ProgId | |
| Write-Host "ProgId for <${extension}> is <${progId}>" | |
| } | |
| else { | |
| Write-Host "No UserChoice key exists for <$extension>" | |
| exit 1 | |
| } | |
| } | |
| catch { | |
| Write-Host "Failed to read ProgId for <$extension> $($_.Exception.Message)" | |
| exit 1 | |
| } | |
| if (-not (Test-Path "Registry::HKEY_CLASSES_ROOT\${progId}")) { | |
| Write-Host "ProgId not registered!" | |
| exit 1 | |
| } | |
| $customProgId = "${progId}_Custom" | |
| if (Test-Path "HKCU:\Software\Classes\${customProgId}") { | |
| Write-Host "CustomProgId <${customProgId}> already defined!" | |
| exit 1 | |
| } else { | |
| reg copy "HKCR\${progId}" "HKCU\Software\Classes\${customProgId}" /s /f | |
| if ($LASTEXITCODE -eq 0) { | |
| Write-Host "ProgId <${progId}> duplicated to <${customProgId}>" | |
| } else { | |
| Write-Host "Duplication of ProgId failed!" | |
| exit 1 | |
| } | |
| } | |
| $applicationKey = "HKCU:\Software\Classes\${customProgId}\Application" | |
| if (-not (Test-Path $applicationKey)) { | |
| New-Item -Path $applicationKey -Force | Out-Null | |
| } | |
| $applicationName = (Get-ItemProperty -Path $applicationKey -Name 'ApplicationName' -ErrorAction SilentlyContinue).ApplicationName | |
| if ($null -eq $applicationName) { | |
| $applicationName = "Custom DefaultApp ($progId)" | |
| } elseif ($applicationName -notmatch '\(Custom\)$') { | |
| $applicationName = "${applicationName} (Custom)" | |
| } | |
| Write-Host "Updating ApplicationName for <${customProgId}> to <${applicationName}>" | |
| Set-ItemProperty -Path $applicationKey -Name "ApplicationName" -Value $applicationName | |
| $defaultIcon = "HKCU:\Software\Classes\${customProgId}\DefaultIcon" | |
| if (-not (Test-Path $defaultIcon)) { | |
| New-Item -Path $defaultIcon -Force | Out-Null | |
| } | |
| Write-Host "Updating CustomProgId DefaultIcon" | |
| Set-ItemProperty -Path $defaultIcon -Name "(Default)" -Value $icon | |
| $extensionKey = "HKCU:\Software\Classes\${extension}" | |
| If (-not (Test-Path $extensionKey)) { | |
| New-Item -Path $extensionKey -Force | Out-Null | |
| } | |
| Write-Host "Updating Extension" | |
| Set-ItemProperty -Path $extensionKey -Name "(Default)" -Value $customProgId | |
| Write-Host "Find a <${extension}> file and use 'Open with' > 'Choose Another App' > select <$applicationName>" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated script to modify the ApplicationName on created custom DefaultApp (easier to see in the choose app dialog) and a few checks to make sure registry keys exist.