16-install-telegram 改用 winget machine-wide + 建 Public Desktop 捷徑

之前用 Telegram 官方 tsetup.exe 即使加 /ALLUSERS 也會 fallback 到 per-user
(PrivilegesRequired=lowest 寫死),裝到 Admin 的 AppData,User 帳號看不到。
改成:
- winget install --scope machine(用 portable 包,所有 user 都能用)
- 抓實際 Telegram.exe 路徑
- 在 C:\Users\Public\Desktop 建立 Telegram.lnk,User 一登入就看得到
This commit is contained in:
2026-04-28 08:41:39 +08:00
parent 29c6ddf982
commit 8fdce82737

View File

@@ -2,8 +2,32 @@
Section 'install-telegram' {
Wait-Network -timeoutSec 30
$p = Join-Path $env:TEMP 'tsetup.exe'
Invoke-WebRequest -UseBasicParsing -Uri 'https://telegram.org/dl/desktop/win64' -OutFile $p
$proc = Start-Process -FilePath $p -ArgumentList '/VERYSILENT','/SUPPRESSMSGBOXES','/NORESTART' -Wait -PassThru
Log "Telegram installer exit code: $($proc.ExitCode)"
# 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.exewinget 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"
# 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"
}