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

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

Open
itoc-dw opened this issue Mar 7, 2024 · 1 comment
Open

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

itoc-dw opened this issue Mar 7, 2024 · 1 comment

Comments

@itoc-dw
Copy link

itoc-dw commented Mar 7, 2024

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
@jeremyts
Copy link

Nice work @itoc-dw. I just enhanced your new code a little to handle both extensions and protocols.

  If ($Extension.Substring(0, [Math]::Min($Extension.Length, 1)) -eq "." ) {
    try {
      If ((Get-FTA -Extension $Extension -ErrorAction Stop) -eq $ProgId) { 
        Write-Verbose "Extension $Extension is already set to $ProgId"
        return
      }
    } 
    catch {
      Write-Verbose "Unable to determine Get-FTA on SET-FTA" -verbose
    }
  } Else {
    try {
      If ((Get-PTA -Protocol $Extension -ErrorAction Stop) -eq $ProgId) { 
        Write-Verbose "Protocol $Extension is already set to $ProgId"
        return
      }
    } 
    catch {
      Write-Verbose "Unable to determine Get-PTA on SET-FTA"
    }
  }

Hope that helps.

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

2 participants