如何编写PowerShell脚本将.ICA文件默认关联至Citrix wfcrun32.exe?
PowerShell脚本设置.ICA文件默认打开程序为Citrix Connection Manager
以下是可直接运行的PowerShell脚本,用于将.ICA文件的默认打开程序指定为Citrix Connection Manager(路径C:\Program Files (x86)\Citrix\ICA Client\wfcrun32.exe):
# 检查CCM程序是否存在 $ccmPath = "C:\Program Files (x86)\Citrix\ICA Client\wfcrun32.exe" if (-not (Test-Path $ccmPath)) { Write-Error "Citrix Connection Manager未找到,请先安装CCM" exit 1 } # 确保以管理员权限运行 $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Error "请以管理员权限运行此脚本" exit 1 } # 定义注册表路径 $icaProgIdPath = "HKLM:\Software\Classes\.ica" $citrixProgIdPath = "HKLM:\Software\Classes\Citrix.ICAClient" $citrixShellPath = "$citrixProgIdPath\shell\open\command" # 创建.ica扩展名关联的ProgID New-Item -Path $icaProgIdPath -Force | Out-Null Set-ItemProperty -Path $icaProgIdPath -Name "(Default)" -Value "Citrix.ICAClient" -Force # 创建Citrix.ICAClient ProgID项 New-Item -Path $citrixProgIdPath -Force | Out-Null Set-ItemProperty -Path $citrixProgIdPath -Name "(Default)" -Value "Citrix ICA Client" -Force Set-ItemProperty -Path $citrixProgIdPath -Name "FriendlyTypeName" -Value "Citrix ICA Client" -Force # 设置默认打开命令 New-Item -Path $citrixShellPath -Force | Out-Null Set-ItemProperty -Path $citrixShellPath -Name "(Default)" -Value "`"$ccmPath`" `"%1`"" -Force # 刷新系统文件关联 $null = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Shell.Application").Namespace(0).ParseName("HKCR:\.ica").InvokeVerb("refresh") Write-Host ".ICA文件默认打开程序已成功设置为Citrix Connection Manager"
脚本说明
- 权限检查:修改系统级注册表需要管理员权限,脚本会先验证当前权限,无权限则退出
- 路径验证:先确认CCM程序是否存在,避免无效操作
- 注册表配置:
- 为
.ica扩展名绑定自定义ProgIDCitrix.ICAClient - 配置ProgID的显示名称
- 设置
open命令指向CCM程序,确保打开.ICA文件时调用正确的程序
- 为
- 关联刷新:调用Shell接口刷新文件关联,无需重启系统即可生效
使用注意事项
- 右键PowerShell选择「以管理员身份运行」
- 确保已安装Citrix Connection Manager,且路径与脚本中一致
- 运行后可通过右键.ICA文件→「打开方式」确认默认程序已更新
内容的提问来源于stack exchange,提问作者TheTypist
相关产品推荐
相关产品推荐

