Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup $allApplicationAssociationToasts handling #27

Open
devinnate opened this issue Jun 12, 2023 · 0 comments
Open

Cleanup $allApplicationAssociationToasts handling #27

devinnate opened this issue Jun 12, 2023 · 0 comments

Comments

@devinnate
Copy link

devinnate commented Jun 12, 2023

Issues:

  1. The code that first initializes $allApplicationAssociationToasts will cause $allApplicationAssociationToasts to be a string, rather than an array, if the original call returns 1 result. This leads to the resultant buildup of a string, not an array, by the subsequent calls, which isn't right.

  2. While fixing this, I rewrote portions of $allApplicationAssociationToasts to be (at least in my opinion) easier to read and troubleshoot. I believe it is functionally identical, however YMMV.

Tested on Powershell 7 w/ StrictMode -Version 3

Submitting my proposed changes back. Sorry that this is just raw code, not a diff. I can convert to diff if desired.


$allApplicationAssociationToasts = @(
  Get-Item -Path HKLM:\SOFTWARE\Classes\$Extension\OpenWithList\* -ErrorAction SilentlyContinue | ForEach-Object {
    "Applications\$($_.PSChildName)"
  })

$allApplicationAssociationToasts += @(
  Get-Item -Path HKLM:\SOFTWARE\Classes\$Extension\OpenWithProgids -ErrorAction SilentlyContinue | ForEach-Object {
    $_.Property | Where-Object { $_ -and $_ -ne "(default)" }
  })

$allApplicationAssociationToasts += @(
  Get-Item -Path HKLM:\SOFTWARE\Clients\StartMenuInternet\*\Capabilities\* , HKCU:\SOFTWARE\Clients\StartMenuInternet\*\Capabilities\* -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -in "URLAssociations", "FileAssociations" } | ForEach-Object {
    if ($_.Property -contains $Extension) {
      Get-ItemPropertyValue -Path $_.PSPath -Name $Extension
    }
  })

$allApplicationAssociationToasts | Where-Object { $_ } | ForEach-Object {
  if (Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts -Name "$($_)_$($Extension)" -Value 0 -Type DWord -ErrorAction SilentlyContinue -PassThru) {
    Write-Verbose  ("Write Reg ApplicationAssociationToastsList OK: " + $_ + "_" + $Extension)
  }
  else {
    Write-Verbose  ("Write Reg ApplicationAssociationToastsList FAILED: " + $_ + "_" + $Extension)
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant