winget 解 portable zip 時,'Telegram\' 內層目錄會 break ACL inheritance, 只剩 Admin/Administrators/SYSTEM,BUILTIN\\Users 沒進去。 即使把 User 加進 Administrators 群組,UAC 雙擊用標準 token 跑時仍被擋, 彈出「無法存取此捷徑所參照的項目,沒有適當的權限」。 修法:winget 裝完之後 icacls /grant BUILTIN\\Users RX 整個 package 目錄樹。 Chrome 沒這個問題(自家 installer 自己處理 ACL),所以只要修 Telegram。
41 lines
2.0 KiB
PowerShell
41 lines
2.0 KiB
PowerShell
. "$PSScriptRoot\_common.ps1"
|
||
|
||
Section 'install-telegram' {
|
||
Wait-Network -timeoutSec 30
|
||
|
||
# Telegram 官方 tsetup.exe 是 Inno Setup PrivilegesRequired=lowest,
|
||
# /VERYSILENT /ALLUSERS 都會 fallback per-user,裝到 Admin 的 AppData
|
||
# 而 User 帳號看不到。改用 winget 的 portable 包 (--scope machine),
|
||
# 所有 user 都能用,並在 Public Desktop 放一個捷徑讓使用者看得到。
|
||
$winget = (Get-Command winget -ErrorAction SilentlyContinue).Source
|
||
if (-not $winget) { Log 'winget not found; skipping Telegram'; return }
|
||
|
||
& $winget install --id Telegram.TelegramDesktop -e --silent --source winget --scope machine `
|
||
--accept-source-agreements --accept-package-agreements 2>&1 |
|
||
ForEach-Object { Log " winget: $_" }
|
||
|
||
# 找實際 Telegram.exe(winget portable 路徑包含版本字尾,動態找)
|
||
$exe = Get-ChildItem 'C:\Program Files\WinGet\Packages' -Recurse -Filter 'Telegram.exe' -EA SilentlyContinue |
|
||
Where-Object { $_.Length -gt 1MB } |
|
||
Select-Object -First 1 -ExpandProperty FullName
|
||
if (-not $exe) { Log 'Telegram.exe not found after winget install'; return }
|
||
Log "Telegram.exe: $exe"
|
||
|
||
# 修 ACL:winget 解 portable zip 時 'Telegram\' 內層目錄會 break inherit,
|
||
# 只剩 Admin/Administrators/SYSTEM,標準 token 的 User 雙擊會「沒有適當的權限」。
|
||
# 強制 grant BUILTIN\Users (S-1-5-32-545) RX 在整個 package 目錄(含子物件)。
|
||
$pkgDir = (Get-Item $exe).Directory.Parent.FullName
|
||
& icacls.exe $pkgDir '/grant' '*S-1-5-32-545:(OI)(CI)RX' '/T' '/C' 2>&1 |
|
||
Select-Object -Last 1 | ForEach-Object { Log " icacls: $_" }
|
||
|
||
# Public Desktop 捷徑(C:\Users\Public\Desktop\Telegram.lnk)
|
||
$lnkPath = Join-Path $env:PUBLIC 'Desktop\Telegram.lnk'
|
||
$shell = New-Object -ComObject WScript.Shell
|
||
$lnk = $shell.CreateShortcut($lnkPath)
|
||
$lnk.TargetPath = $exe
|
||
$lnk.WorkingDirectory = (Split-Path $exe -Parent)
|
||
$lnk.IconLocation = $exe
|
||
$lnk.Save()
|
||
Log "Created Public desktop shortcut: $lnkPath"
|
||
}
|