# Slack Compatibility Setting for Citrix Environments # ---------------------------------------------------------------------------- # # This sets a registry key to exempt the Slack binary from Citrix DLL hooking. # The script needs to run with administrive rights and will elevate if necessary. # # Compatible with Windows 10 # ---------------------------------------------------------------------------- <# .SYNOPSIS Make Slack compatible in Citrix environments .DESCRIPTION Certain Citrix software uses DLL hooking to intercept API calls. Starting with Slack Desktop 4.0.x one or more of the hooks stopped working and caused crashes and or delayed startup of Slack. .EXAMPLE ./citrix-workaround.ps1 #> $regPathsCtxHook = @('HKLM:\SOFTWARE\Citrix\CtxHook\', 'HKLM:\SOFTWARE\Wow6432Node\Citrix\CtxHook', 'HKLM:\SOFTWARE\Wow6432Node\Citrix\CtxHook64') $regValueCtxHook = 'ExcludedImageNames' $regPathsCtxUvi = @('HKLM:\SYSTEM\CurrentControlSet\Services\CtxUvi') $regValueCtxUvi = 'UviProcessExcludes' $slack = 'slack.exe' function Get-IsAdmin() { $windowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent() $windowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($windowsID) $adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator return $windowsPrincipal.IsInRole($adminRole); } #launch an admin session if we are not already admin $isAdmin = Get-IsAdmin; if($isAdmin -eq $FALSE) { $adminProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell"; $adminProcess.Arguments = $myInvocation.MyCommand.Definition; $adminProcess.Verb = "runas"; [System.Diagnostics.Process]::Start($adminProcess); exit } function Set-RegPath($regPath) { if(!(Test-Path $regPath)) { New-Item $regPath -Force | Out-Null } } function Set-RegValue($regPath, $regValue, $seperator) { $valueExists = $FALSE $value = '' try { $val = Get-ItemProperty -Path $regPath -Name $regValue -ErrorAction Stop if($regValue -eq $regValueCtxHook) { $value = $val.ExcludedImageNames.Trim(" ", $seperator) $valueExists = $TRUE } elseif ($regValue -eq $regValueCtxUvi) { $value = $val.UviProcessExcludes.Trim(" ", $seperator) $valueExists = $TRUE } } catch { } if($valueExists) { if($value.contains($slack) -eq $FALSE) { if($value.length -gt 0) { $newValue = $value + $seperator } $newValue = $newValue + $slack Set-ItemProperty -Path $regPath -Name $regValue -Value $newValue } } else { New-ItemProperty -Path $regPath -Name $regValue -Value $slack Write-Host "-Path" + $regPath + "-Name" + $regValue + "-Value" + $slack } } foreach ($regPath in $regPathsCtxHook) { Set-RegPath $regPath Set-RegValue $regPath $regValueCtxHook "," } foreach ($regPath in $regPathsCtxUvi) { Set-RegPath $regPath Set-RegValue $regPath $regValueCtxUvi ";" }