Files
windows-unattend/steps/07-apply-ui-ime-default-profile.ps1
Timmy a7975343c3 07:在桌面顯示「本機」與「控制台」(Default profile + 已載入 user hive)
寫到 HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons
底下的 NewStartPanel + ClassicStartMenu 兩個 key(NewStartPanel 是 Win11 用、
ClassicStartMenu 為相容性也寫一份)。值 0=顯示,1=隱藏。

腳本內保留 5 個內建 CLSID 對照表註解,未來要新增/移除其他圖示
(使用者檔案 / 網路 / 資源回收筒)只需動 $showOnDesktop 陣列。
2026-04-28 08:58:50 +08:00

102 lines
4.5 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
. "$PSScriptRoot\_common.ps1"
# Apply UI/IME settings to (a) Default profile NTUSER.DAT (so brand-new users
# inherit) and (b) every currently-loaded real-user hive (so re-runs against
# an already-logged-in box still take effect immediately on those users).
function Apply-UiImeSettings {
param([string]$base) # e.g. "Registry::HKU\SetupDefault" or "Registry::HKEY_USERS\<SID>"
$adv = "$base\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Set-RegValue $adv 'HideFileExt' 0
Set-RegValue $adv 'Hidden' 1
Set-RegValue $adv 'TaskbarAl' 0
Set-RegValue $adv 'ShowTaskViewButton' 0
Set-RegValue $adv 'LaunchTo' 1
Set-RegValue $adv 'Start_TrackProgs' 0
$theme = "$base\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"
Set-RegValue $theme 'AppsUseLightTheme' 0
Set-RegValue $theme 'SystemUseLightTheme' 0
$search = "$base\Software\Microsoft\Windows\CurrentVersion\Search"
Set-RegValue $search 'SearchboxTaskbarMode' 0
# SearchSettings 在某些 build 上 reg.exe 會「存取被拒」Win11Debloat 的
# Disable_Search_History.reg 跟 Disable_Search_Highlights.reg 都會撞),
# 但 PowerShell .NET API 寫得進去——這裡一次處理掉Win11Debloat config 已把這兩項移除
$searchSettings = "$base\Software\Microsoft\Windows\CurrentVersion\SearchSettings"
Set-RegValue $searchSettings 'IsDeviceSearchHistoryEnabled' 0
Set-RegValue $searchSettings 'IsDynamicSearchBoxEnabled' 0
$cloud = "$base\Software\Policies\Microsoft\Windows\CloudContent"
Set-RegValue $cloud 'DisableSpotlightCollectionOnDesktop' 1
Set-RegValue $cloud 'DisableWindowsSpotlightFeatures' 1
# 鍵盤排序:英文鍵盤排第一(預設英數),注音排第二
$kbPre = "$base\Keyboard Layout\Preload"
Set-RegValue $kbPre '1' '00000409' 'String'
Set-RegValue $kbPre '2' '00000404' 'String'
# CHT 注音:預設英數模式、關掉雲端候選與預測
$cht = "$base\Software\Microsoft\InputMethod\Settings\CHT"
Set-RegValue $cht 'Enable Default Input Mode' 0
Set-RegValue $cht 'Enable Cand Predict' 0
Set-RegValue $cht 'Enable Cloud Cand' 0
Set-RegValue $cht 'Enable Cloud Input' 0
# 把系統 Hotkey 切換鍵停掉3 = 不指定鍵)
$tg = "$base\Keyboard Layout\Toggle"
Set-RegValue $tg 'Hotkey' '3' 'String'
Set-RegValue $tg 'Language Hotkey' '3' 'String'
Set-RegValue $tg 'Layout Hotkey' '3' 'String'
# 桌面圖示顯示控制HideDesktopIcons0=顯示1=隱藏;
# NewStartPanel 是 Win11 用的 keyClassicStartMenu 是舊版相容)
# 內建可控的 5 個 CLSID
# 1 本機 This PC {20D04FE0-3AEA-1069-A2D8-08002B30309D}
# 2 使用者檔案 User's Files {59031A47-3F72-44A7-89C5-5595FE6B30EE}
# 3 網路 Network {F02C1A0D-BE21-4350-88B0-7367FC96EF3C}
# 4 資源回收筒 Recycle Bin {645FF040-5081-101B-9F08-00AA002F954E}
# 5 控制台 Control Panel {5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}
# 目前需求:顯示「本機」與「控制台」(資源回收筒 Win11 預設就有)
$showOnDesktop = @(
'{20D04FE0-3AEA-1069-A2D8-08002B30309D}', # This PC
'{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}' # Control Panel
)
foreach ($keyName in @('NewStartPanel','ClassicStartMenu')) {
$hk = "$base\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\$keyName"
foreach ($clsid in $showOnDesktop) {
Set-RegValue $hk $clsid 0
}
}
}
Section 'apply-ui-ime-default-profile' {
# (a) Default profile新使用者首次登入會繼承
$hivePath = 'C:\Users\Default\NTUSER.DAT'
$mountKey = 'HKU\SetupDefault'
reg.exe load $mountKey $hivePath | Out-Null
try {
Apply-UiImeSettings "Registry::$mountKey"
Log "Applied to Default profile"
} finally {
[GC]::Collect()
Start-Sleep 1
reg.exe unload $mountKey | Out-Null
}
# (b) 已載入的真人 user hiveHKU\<SID>,跳過 .DEFAULT / 系統 SID
# 取自 Win32_UserProfile過濾 Special只在 hive 已載入時寫
$profiles = Get-CimInstance Win32_UserProfile -ErrorAction SilentlyContinue |
Where-Object { -not $_.Special }
foreach ($p in $profiles) {
$sid = $p.SID
if (Test-Path "Registry::HKEY_USERS\$sid") {
Apply-UiImeSettings "Registry::HKEY_USERS\$sid"
Log ("Applied to live user hive {0} ({1})" -f $sid, (Split-Path $p.LocalPath -Leaf))
} else {
Log ("Skip {0} ({1}) - hive not loaded" -f $sid, (Split-Path $p.LocalPath -Leaf))
}
}
}