Skip to content

Set-FTA flashes all icons on the desktop.  #34

@itoc-dw

Description

@itoc-dw

Hi, This project has been very useful for our team, so thank you sharing.

We had various customers on Azure Virtual Desktop reporting that their screen constantly flashes each time Set-FTA is run. To limit the flashing, we altered the code to within Set-FTA to only execute if it differs by using Get-FTA which is significantly quicker as well when using the measure-command.

Not sure if it breaks it for any other functions as we don't use all functionality but thought I might share it if its useful.


#### Set-FTA causes flashes of icons on the desktop when it executed. Get-FTA does not have this problem
#### Get-FTA takes 5-10ms. Set-FTA takes 500ms.

function Set-FTA {

  [CmdletBinding()]
  param (
    [Parameter(Mandatory = $true)]
    [String]
    $ProgId,

    [Parameter(Mandatory = $true)]
    [Alias("Protocol")]
    [String]
    $Extension,
      
    [String]
    $Icon
  )
  
  if (Test-Path -Path $ProgId) {
    $ProgId = "SFTA." + [System.IO.Path]::GetFileNameWithoutExtension($ProgId).replace(" ", "") + $Extension
  }

  Write-Verbose "ProgId: $ProgId"
  Write-Verbose "Extension/Protocol: $Extension"

  #### START NEW CODE
  try {
    if ((Get-FTA -Extension $Extension -ErrorAction Stop) -eq $ProgId) { 
        Write-Verbose "Extension $Extension is already set to $ProgId"
        return 
    }
    else {
        Write-Output "Extension $Extension required to be set to $ProgId"
    }
  } 
  catch {
    Write-Verbose "Unable to determine Get-FTA on SET-FTA "
  }
  #### END NEW CODE

  function local:Update-RegistryChanges {
    $code = @'
    [System.Runtime.InteropServices.DllImport("Shell32.dll")] 
    private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
    public static void Refresh() {
        SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero);    
    }
'@ 

    try {
      Add-Type -MemberDefinition $code -Namespace SHChange -Name Notify
    }
    catch {}

    try {
      [SHChange.Notify]::Refresh()
    }
    catch {} 
  }


##### TRUNCATED

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