Skip to content

Cleanup $allApplicationAssociationToasts handling #27

@devinnate

Description

@devinnate

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)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions