2020年10月9日

不要讓Windows 10被Windows Update升級大版本

(只是想要快速透過Windows Update立即更新到21H1的, 請參考底下匯入註冊機碼的範例)

Windows 10這幾年來大概都維持一年兩次[功能更新]版本(version), 每個版本的生命週期原則上為18或30個月(從發行日期起算).

使用Windows Update更新系統時, 可能會一不小心就被自動升級到新的版本. 如果想要使用Windows Update安裝[安全性更新], 但是又不想要順便被[功能更新](大版本升級)或是被提示有[功能更新], 可以透過群組原則或是註冊機碼來達成.

從Windows 10 版本1803起, 可以透過設定註冊機碼[TargetReleaseVersionInfo]來指定想要的Windows 10版本.
[Windows 10 版本(version)]與[終止服務(end of service)]日期 請參考這裡: Windows 10 版本資訊


[TargetReleaseVersionInfo]的版本號如果:
比現有Windows 10的版本號: 

  • 通常不會這樣設定, 經測試是會停留在原有的版本 (請參考後面的測試結果)


等於現有Windows 10的版本號:

  • Windows Update僅會基於現有的版本號安裝[安全性更新], 不會下載安裝[功能更新](大版本升級)或是提示有[功能更新], 但是可能會提示Windows版本[已終止服務]或是[即將終止服務]
  • 需注意的是按照微軟的說法, 這個設定並不是永久有效的, 如果現有的Windows 10版本已經過了[終止服務(end of service)]日期, 可能還是會被提示有[功能更新]. 我用已經過了[終止服務]日期的版本1803[專業版]測試, 目前並未發現會被強迫升級, 但是有提示:"您的Windows版本已終止服務...建議更新至最新版本的Windows 10". (請參考後面的測試結果)


比現有Windows 10的版本號: (必須是已經有推送的版本號) 

  • Windows Update會直接下載安裝[功能更新]到指定的版本號
    (所以想跳過某些版本號, 直接升級到後面的版本可以用這方法)
  • 升級完後[TargetReleaseVersionInfo]就變成等於現有Windows 10的版本號
  • 設定大於目前有推送的版本號(尚未推出的版本), 經測試是會停留在原有的版本 (請參考後面的測試結果)


設定方法(一): 用PowerShell script設定 
  • 下載檔案 SetTargetVersion.ps1
  • 在[SetTargetVersion.ps1]檔案上按滑鼠右鍵選[用 PowerShell 執行]
  • 輸入要設定的版本號碼, 如果直接按enter(沒輸入版本號碼), 則使用目前Windows 10的版本號碼當作指定的版本
  • 確定後即設定完成

如果要刪除/清空設定:

  • 在要輸入設定的版本號碼時, 輸入0

設定方法(二): 匯入註冊機碼

1
2
3
4
5
6
7
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"TargetReleaseVersion"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"TargetReleaseVersionInfo"="2105"

如果要刪除/清空設定:

1
2
3
4
5
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"TargetReleaseVersion"=-
"TargetReleaseVersionInfo"=-


以下是我用各種設定做的測試, 可以參考不同設定會造成的效果:

  • 測試是在2020/10/05~10/11間進行, 版本2009/20H2在當時尚未推出
  • 停留在某一個版本號時, 均可以正常下載安裝該版本的[安全性更新]
  • 測試使用: Windows 10 繁體中文[專業版]
  • 1803 [專業版] EOS: 2019-11-12
  • 1809 [專業版] EOS: 2020-11-10


 
以下是一些測試的截圖:
  • 1803, 無設定, 升級到1909, 提示會有2004功能更新(無"下載並安裝")
 


  • 1803, 設定為1803, 停留在1803, 提示"您的Windowsb版本已終止服務"
 


  • 1809, 設定為1803, 停留在1809, 提示"您目前執行的Windows版本即將終止服務" (1809 [專業版] EOS: 2020-11-10)
 


  • 1903, 無設定, 停留在1903, 提示有2004功能更新("下載並安裝")
 

2020/10/21 補充:
版本20H2已在今天推出, 在微軟網頁公布的已經不是全數字的版本號, 而是20H2

版本20H2比起版本2004(含)以前的版本, 註冊機碼多了[DisplayVersion], [ReleaseId]則是2009

[TargetReleaseVersionInfo]經我測試使用2009或是20H2都無效, 反而是要設定成2010才有效.
可能要等晚些時候再看看有沒有更多的資訊會公布
 
  • 1809, 設定為2010, 直接升級20H2
 
 
2020/11/10 補充:

以下是我在Windows 10 20H2推出後所做的測試, 可以參考不同設定會造成的效果:

  • 測試是在2020/10/23~10/28間進行
  • 測試使用: Windows 10 繁體中文[專業版]


2021/05/20 補充:
版本21H1已在今天推出, [TargetReleaseVersionInfo]經我測試設定成2105可以升級到21H1.
  • 1909, 設定為2105, 直接升級21H1



2020年9月20日

Windows 10 安裝[舊版][新倉頡][新速成]中文輸入法 (Windows 11適用)

微軟從Windows 10 版本2004 (20H1)開始推出新的中文輸入法, 有些軟體還不能完全相容.

如果想要用以前版本的新倉頡或是新速成輸入法, 需要動點手腳才能安裝.

所需的步驟要改好些地方(設定, 註冊機碼...), 我把它寫成一個PowerShell檔, 只要執行就可以設定安裝舊版的新倉頡跟新速成輸入法.

目前在Windows 10 22H2 19045.x / Windows 11 22H2 22621.x上測試都還可以用, 至於以後更新版的Windows推出後還能不能繼續這樣用就不知了.

使用方法:

  • 下載檔案 AddNewIME.ps1
  • 至少要安裝[微軟注音]輸入法
  • 在[AddNewIME.ps1]檔案上按滑鼠右鍵選[用 PowerShell 執行]即可


有安裝測試過的版本:
Windows 11 專業版 (繁體中文) 64位元版

  • 版本 22H2
  • 版本 21H2

Windows 10 專業版 (繁體中文) 64位元版

  • 版本 22H2
  • 版本 21H2
  • 版本 21H1
  • 版本 20H2
  • 版本 2004/20H1
  • 版本 1909/19H2
  • 版本 1903/19H1
  • 版本 1809/RS5

 

2020/12/01 補充:

如果要在繁中語系裡面像以前一樣有US鍵盤: (不太建議這樣使用)

  • 下載檔案 AddNewIMEandQWERTY.ps1
  • 在[AddNewIMEandQWERTY.ps1]檔案上按滑鼠右鍵選[用 PowerShell 執行]即可 


2020年6月15日

Windows Terminal 設定

Windows Terminal剛裝好時大概長這樣, 內容會因為你裝的東西有些不同:


點開設定可以看到settings.json大概長這樣:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// This file was initially generated by Windows Terminal 1.0.1401.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",

    // You can add more global application settings here.
    // To learn more about global settings, visit https://aka.ms/terminal-global-settings

    // If enabled, selections are automatically copied to your clipboard.
    "copyOnSelect": false,

    // If enabled, formatted data is also copied to your clipboard
    "copyFormatting": false,

    // A profile specifies a command to execute paired with information about how it should look and feel.
    // Each one of them will appear in the 'New Tab' dropdown,
    //   and can be invoked from the commandline with `wt.exe -p xxx`
    // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "命令提示字元",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
                "hidden": false,
                "name": "PowerShell",
                "source": "Windows.Terminal.PowershellCore"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
                "hidden": false,
                "name": "Ubuntu-20.04",
                "source": "Windows.Terminal.Wsl"
            }
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [],

    // Add custom keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about keybindings, visit https://aka.ms/terminal-keybindings
    "keybindings":
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
        { "command": "paste", "keys": "ctrl+v" },

        // Press Ctrl+Shift+F to open the search box
        { "command": "find", "keys": "ctrl+shift+f" },

        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
    ]
}

可以使用的選項是Windows Terminal根據系統內有安裝的東西自動產生的, 每一項會對應到一個"profile", 以"guid"當作獨特的識別


由"defaultProfile"的"guid"可以看出預設開啟的是"PowerShell",
如果想改成預設開啟"命令提示字元", 把"defaultProfile"的"guid"改為"{0caa0dad-35be-5f56-a8ff-afceeeaa6101}"即可

因為profile是Windows Terminal自動產生的, 如果有些選項不想用, 不能直接刪掉某個profile(會再產生回來), 要把"hidden"改為true, 至於porfile的順序則可以自己調動

以下是修改了:
  • 預設開啟"命令提示字元", 並把選項順序改到最上面
  • 不顯示"Azure Cloud Shell"


如果要修改Windows Terminal的色彩配置, 可以加在:
  • "defaults": 所有的profiles都會套用
  • 個別profile: 僅該profile會套用
以下是修改了:
  • "命令提示字元" profile: 使用Windows Terminal內建的"One Half Light"色彩配置, 並開啟壓克力效果


Windows Terminal內建的色彩配置有:
  • Campbell
  • Campbell Powershell
  • Vintage
  • One Half Dark
  • One Half Light
  • Solarized Dark
  • Solarized Light
  • Tango Dark
  • Tango Light

色彩配置的內容及效果請參考:
https://docs.microsoft.com/zh-tw/windows/terminal/customize-settings/color-schemes

加上 startingDirectory 可以設定起始目錄:


修改過的settings.json:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// This file was initially generated by Windows Terminal 1.0.1401.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",

    // You can add more global application settings here.
    // To learn more about global settings, visit https://aka.ms/terminal-global-settings

    // If enabled, selections are automatically copied to your clipboard.
    "copyOnSelect": false,

    // If enabled, formatted data is also copied to your clipboard
    "copyFormatting": false,

    // A profile specifies a command to execute paired with information about how it should look and feel.
    // Each one of them will appear in the 'New Tab' dropdown,
    //   and can be invoked from the commandline with `wt.exe -p xxx`
    // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles. (如果要所有的profiles都套用就加在這下面)
        },
        "list":
        [
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "命令提示字元",
                "commandline": "cmd.exe",
                "colorScheme": "One Half Light",
                "useAcrylic": true,
                "startingDirectory": "%USERPROFILE%\\Desktop",
                "hidden": false
            },
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
                "hidden": false,
                "name": "PowerShell",
                "source": "Windows.Terminal.PowershellCore"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": true,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
                "hidden": false,
                "name": "Ubuntu-20.04",
                "source": "Windows.Terminal.Wsl"
            }
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [],

    // Add custom keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about keybindings, visit https://aka.ms/terminal-keybindings
    "keybindings":
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
        { "command": "paste", "keys": "ctrl+v" },

        // Press Ctrl+Shift+F to open the search box
        { "command": "find", "keys": "ctrl+shift+f" },

        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
    ]
}


2020年5月23日

試玩 winget tool


微軟在今年的Mircosoft Build上發表了一個可以用來安裝應用程式的命令列工具: winget tool
目前還是preview的winget tool可以在Windows Terminal, PowerShell或是命令提示字元(Command Prompt)下執行

以下操作使用的是: Windows 10(版本 2004/19041.264)繁體中文專業版

首先下載Windows Package Manager Preview版來安裝(winget tool包含在其中)
下載Assets底下的: Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle
點兩下就可以安裝:


出現第二個視窗就裝好了, 直接關掉即可

winget tool有開放原始碼, 工具簡介與使用說明 原始碼:

打開PowerShell來測試:


看別人使用好像很簡單, 我就來試試用winget安裝PowerShell 7的穩定版:
winget install powershell 咦, 不行
加個參數看看: winget install -e Powershell 搞定

2020/05/26: 今天發現winget search powershell多了Powershell Core 7.0.0版, 7.0.1版的PowerShell, S變成大寫字母
所以要這樣才能安裝7.0.1版: winget install -e "PowerShell" --id "Microsoft.PowerShell"


接下來換用PowerShell 7操作, 用winget安裝個新版的Microsoft Edge看看:
winget search "Microsoft Edge"
winget install "Microsoft Edge" 果然不行
加參數: winget install -e "Microsoft Edge" 還是不行
加更多參數: winget install -e "Microsoft Edge" --id "Microsoft.Edge" 終於可以了


大亂鬥, 比一下用Invoke-WebRequest下載PowerShell 7後安裝跟用winget tool安裝哪個快: (PowerShell-7.0.1-win-x64.msi 檔案大小約 86.9 MB)
1
2
3
4
5
6
7
$ProgressPreference = 'SilentlyContinue'
Measure-Command -Expression { 
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    $ProgressPreference = 'SilentlyContinue'
    Invoke-WebRequest -UseBasicParsing -Uri https://github.com/PowerShell/PowerShell/releases/download/v7.0.1/PowerShell-7.0.1-win-x64.msi -OutFile "$env:TEMP\PowerShell-7.0.1-win-x64.msi"
    Start-Process "msiexec.exe" -ArgumentList "/package $env:TEMP\PowerShell-7.0.1-win-x64.msi /quiet" -Wait
}


1
2
3
Measure-Command -Expression {
    winget install -e "PowerShell" --id "Microsoft.PowerShell" -h
}



結果用winget tool慢一點 (36.83秒 vs. 39.54秒)

2020/11/01: 調整一些有關winget的設定, 首先用winget settings打開設定檔

(設定檔格式與參數說明: 在此)

改成這樣後存檔:

{
    // For documentation on these settings, see: https://aka.ms/winget-settings
    // "source": {
    //    "autoUpdateIntervalInMinutes": 5
    // },
    "$schema": "https://aka.ms/winget-settings.schema.json",
    "visual": {
        "progressBar": "rainbow"
    },
   "experimentalFeatures": {
       "experimentalCmd": true,
       "experimentalArg": true,
       "experimentalMSStore": true
   }
}

  • Source/autoUpdateIntervalInMinutes: winget更新來源(source)資料的間隔時間 (我用預設值就不改了)
  •  $schema: default schema
  • Visual/progressBar: 安裝軟體時進度條的樣式, 改成彩虹樣式是像這樣:

打開實驗功能 Experimental Features:

  • experimentalCmd
  • experimentalArg
  • experimentalMSStore: 開啟安裝Microsoft Store App的功能

測試一下打開實驗功能後的效果:

  • winget features : 查看實驗功能運行的狀態
  • winget source list : 列出目前的來源
  • winget source update : 更新目前的來源
  • winget search "Windows Terminal" : 搜尋"Windows Terminal" (所有來源)
  • winget search "Windows Terminal" -s msstore : 搜尋"Windows Terminal" (只限Microsoft Store)
  • winget install "Windows Terminal" -s msstore : 從Microsoft Store安裝"Windows Terminal" (目前需要先登入Microsoft Store才可以下載安裝)
  • winget install "Windows Terminal" -s winget : 改從winget-pkgs安裝"Windows Terminal"
 
  •  如果有登入Microsoft Store, winget install "Windows Terminal" -s msstore :



2020年4月28日

PMax 如何用 Windows系統映像管理員(Windows System Image Manager) 製作Windows 10自動安裝回應檔案
PART Max 懶人包


PART I 準備工作
PART II 瞭解Windows 10安裝過程
PART III 製作自動安裝回應檔案
PART IV 如何使用
PART V 關閉[SMB 1.0/CIFS 檔案共用支援]功能
PART VI 使用DiskPart建立磁碟分割
PART VII 不要預留[保留的儲存空間]
PART VIII 指定電腦名稱與加入網域
PART IX 彈性搭配批次檔使用
PART Max 懶人包

使用方法:
改動Windows 10原版ISO內容:
  • 下載檔案
  • 把autounattend.xml和partition.cmd複製到Windows 10安裝媒體/(ISO檔案裡)的 根目錄(跟setup.exe同一層)
  • 把其餘所有檔案複製到Windows 10安裝媒體/(ISO檔案裡)的 sources\$OEM$\$$\Setup\Scripts
  • 使用該安裝媒體安裝Windows 10

不改動Windows 10原版ISO內容, 外掛使用floppy disk的映像檔:

2020/05/29: 增加了使用winget安裝應用程式的選擇


有安裝測試過的版本:
Windows 11 專業版 (繁體中文) 64位元版

  • Windows 11 Insider Preview Build 22572.1
  • Windows 11 版本 21H2 Build 22000.556

Windows 10 專業版 (繁體中文) 64位元版

  • 版本 2009/21H2 Build 19044.1586
  • 版本 2009/21H1
  • 版本 2009/20H2
  • 版本 2004/20H1
  • 版本 1909/19H2 
  • 版本 1903/19H1 
  • 版本 1809/RS5

安裝流程說明:
autounattend.xml
[windowsPE]階段
  • 把安裝媒體的磁碟機代號設為Z
  • 執行z:\partition.cmd: 判斷是BIOS還是UEFI模式, 呼叫DiskPart分割磁碟
  • 安裝Windows 10專業版

[specialize]階段
  • 產生電腦名稱: ABCIT-XXXXXXXXX (X表示為隨機產生的字元)
  • 停用[保留的儲存空間]
  • 停用[首次登入動畫(first sign-in animation)]

[oobeSystem]階段
  • 建立本地帳號, 使用者: admin, 密碼: password
  • 用admin帳號自動登入
  • 把微軟注音輸入法的[預設輸入模式]改為英數字元(alphanumeric)
  • 執行MyPost.cmd
  • MyPost.cmd執行完成後, 設定系統於180秒後重新啟動

MyPost.cmd
  • 停用[SMB 1.0/CIFS 檔案共用支援]功能
  • 把admin帳號設為密碼永久有效
  • 設定工作管理員顯示更多詳細資料 (執行SetTaskManager.ps1)
  • 選擇電源計畫[平衡]並設定:
    • 關閉顯示器: 30分鐘
    • 讓電腦睡眠: 永不
    • 硬碟, 關閉硬碟前的時間: 0分鐘(永不)
  • 修改使用者跟預設的註冊機碼
    • Turn off [Start OneDrive automatically when sign in to Windows]
    • Show Search icon (instead of box)
    • Hide Cortana button
    • Disable People Bar on taskbar
    • Show This PC icon
    • Show Network icon
    • Show Control Panel icon
    • Show File name extensions
    • UAC Do not dim my deskyop
    • Disable Acrylic Background On Logon
    • Set More details in File Transfer Dialog
    • Hide Meet Now icon, OS build 18362 and later
    • Windows 11 only
      • Set Taskbar alignment Left
      • Uninstall Microsoft Teams for all users
    • Disable Open on hover for News and interests, OS build 18363 later
    • Set AutoLogonCount to 0
    • Set Default Input Mode to Alphanumeric
    • Set More details in Task Manager
    • Disable first sign-in animation
  • 選用步驟: (每個步驟會詢問是否執行, 等待60秒未回答則跳過不執行)
    • DnInWinget.ps1: 詢問是否要下載並安裝winget command line tool, 以及要不要用winget來安裝後面的應用程式
    • DnInChromiumEdge.ps1: 下載並安裝以Chromium為基礎的新Microsoft Edge
    • DnInPowerShell.ps1: 從GitHub下載並安裝PowerShell
    • DnInWinTerminal.ps1: 從GitHub下載並安裝Windows Terminal
    • DnInVcRedist.ps1: 下載並安裝Microsoft Visual C++ 2015-2019 Redistributable x64/x86
    • AddIMEs.ps1: 安裝舊版微軟[新倉頡][新速成]中文輸入法, 參考 Windows 10 安裝新倉頡新速成中文輸入法 (2004/20H1/20H2適用)
    • DnInVMwareTools.ps1: 下載並安裝VMware Tools (VMware Workstation VM)
    • SetTargetVersion.ps1: 設定Windows 10版本, 參考 不要讓Windows 10被Windows Update升級大版本
    • RenCompName.ps1: 更改電腦名稱 
    注意: DnInWinget.ps1 DnInWinTerminal.ps1 會透過 https://store.rg-adguard.net 查詢package的下載連結(package檔案是從微軟網站下載), 如有顧慮就請不要使用
  • 刪除%Systemroot%\Setup\Scripts裡面的所有檔案

(MyPost.cmd執行完成, 系統於180秒後會重新啟動)


以下是我用做好的自動安裝回應檔案在VM上安裝Windows 10的過程畫面
(參考用, 不見得會跟使用下載檔案安裝過程一模一樣, 因為可能還會上傳修改過的回應檔跟script)


2020年4月14日

P9 如何用 Windows系統映像管理員(Windows System Image Manager) 製作Windows 10自動安裝回應檔案
PART IX 彈性搭配批次檔使用


PART I 準備工作
PART II 瞭解Windows 10安裝過程
PART III 製作自動安裝回應檔案
PART IV 如何使用
PART V 關閉[SMB 1.0/CIFS 檔案共用支援]功能
PART VI 使用DiskPart建立磁碟分割
PART VII 不要預留[保留的儲存空間]
PART VIII 指定電腦名稱與加入網域
PART IX 彈性搭配批次檔使用
PART Max 懶人包

如果想要開啟, 修改或關閉Windows 10大部分的功能或屬性, 通常可以透過DISM指令, 修改註冊機碼或是使用PowerShell等不同方法來達成.
要使用自動安裝回應檔案來完成上述目的, 可能寫法比較複雜或是無法做到, 這時就可以搭配批次檔處理比較複雜的設定任務.

首先要注意的事情是: 批次檔是在oobeSystem階段執行的, 也就是那時Windows 10基本上已經安裝完成了.
所以如果有些東西必須要在oobeSystem階段之前就完成的, 例如: P4 不要預留[保留的儲存空間](要在specialize階段就設定好), 那就還是要透過自動安裝回應檔案來完成.

流程:
  • autounattend.xml: 安裝Windows 10專業版
  • autounattend.xml: 產生電腦名稱: ABCIT-XXXXXXXXX (X表示為隨機產生的字元)
  • autounattend.xml: 停用[保留的儲存空間]
  • autounattend.xml: 建立使用者: admin, 密碼: password
  • autounattend.xml: 用admin帳號自動登入, 把中文輸入法的預設輸入模式改設為英數模式
  • autounattend.xml: 執行MyPost.cmd
  • MyPost.cmd: 停用[SMB 1.0/CIFS 檔案共用支援]功能
  • MyPost.cmd: 詢問是否執行RenCompName.ps1, 等待100秒未回答則跳過不執行
  • RenCompName.ps1: 等待輸入要變更的新名稱, 輸入完成並確定後更改為新的電腦名稱
  • MyPost.cmd: 刪除%Systemroot%\Setup\Scripts裡面的所有檔案 (MyPost.cmd, RenCompName.ps1)
  • autounattend.xml: 系統於180秒後重啟

自動安裝回應檔案(autounattend.xml)內容主要來自:
  • P3
  • P4
  • P7
  • P8: 指定電腦名稱的部分

透過批次檔(MyPost.cmd)處理:
  • P5: 改由呼叫PowerShell處理
  • 輸入/更改電腦名稱: 呼叫PowerShell(RenCompName.ps1)處理

原理:
Windows 10安裝媒體/(ISO檔案裡)的 sources\$OEM$\$$\Setup\Script 目錄下的檔案,
在Windows安裝過程中會被複製到 %Systemroot%\Setup\Scripts 目錄 (通常是C:\Windows\Setup\Scripts)

利用自動安裝回應檔案autounattend.xml裡面的<AutoLogon><FirstLogonCommands><SynchronousCommand wcm:action="add">等設定去執行MyPost.cmd, 再進而執行RenCompName.ps1


使用方法:
  • 檔案1. autounattend.xml
  • 檔案2. MyPost.cmd
  • 檔案3. RenCompName.ps1
 
  1. 把檔案1.autounattend.xml複製到Windows 10安裝媒體/(ISO檔案裡)的 根目錄
  2. 把檔案2.MyPost.cmd和檔案3.RenCompName.ps1複製到Windows 10安裝媒體/(ISO檔案裡)的 sources\$OEM$\$$\Setup\Scripts
    • 因為檔案3.內有中文字元, 檔案編碼需要是UTF-16 LE/UCS-2 LE BOM顯示才不會亂碼
  3. 使用該安裝媒體安裝Windows 10

檔案1. autounattend.xml
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<!-- By Proliantaholic https://proliantaholic.blogspot.com -->
    <settings pass="windowsPE">
        <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SetupUILanguage>
                <UILanguage>zh-TW</UILanguage>
            </SetupUILanguage>
            <InputLocale>zh-TW</InputLocale>
            <SystemLocale>zh-TW</SystemLocale>
            <UILanguage>zh-TW</UILanguage>
        </component>
        <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <UserData>
                <ProductKey>
                    <Key>W269N-WFGWX-YVC9B-4J6C9-T83GX</Key>
                    <WillShowUI>OnError</WillShowUI>
                </ProductKey>
                <AcceptEula>true</AcceptEula>
            </UserData>
            <DiskConfiguration>
                <Disk wcm:action="add">
                    <CreatePartitions>
                        <CreatePartition wcm:action="add">
                            <Order>1</Order>
                            <Size>500</Size>
                            <Type>Primary</Type>
                        </CreatePartition>
                        <CreatePartition wcm:action="add">
                            <Extend>true</Extend>
                            <Order>2</Order>
                            <Type>Primary</Type>
                        </CreatePartition>
                    </CreatePartitions>
                    <ModifyPartitions>
                        <ModifyPartition wcm:action="add">
                            <Active>true</Active>
                            <Format>NTFS</Format>
                            <Label>System Reserved</Label>
                            <Order>1</Order>
                            <PartitionID>1</PartitionID>
                        </ModifyPartition>
                        <ModifyPartition wcm:action="add">
                            <Format>NTFS</Format>
                            <Letter>C</Letter>
                            <Order>2</Order>
                            <PartitionID>2</PartitionID>
                        </ModifyPartition>
                    </ModifyPartitions>
                    <DiskID>0</DiskID>
                    <WillWipeDisk>true</WillWipeDisk>
                </Disk>
                <WillShowUI>OnError</WillShowUI>
            </DiskConfiguration>
            <ImageInstall>
                <OSImage>
                    <InstallFrom>
                        <MetaData wcm:action="add">
                            <Key>/IMAGE/DISPLAYNAME</Key>
                            <Value>Windows 10 專業版</Value>
                        </MetaData>
                    </InstallFrom>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>2</PartitionID>
                    </InstallTo>
                </OSImage>
            </ImageInstall>
        </component>
    </settings>
    <settings pass="specialize">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="NonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <RegisteredOwner>ABC</RegisteredOwner>
            <RegisteredOrganization>IT</RegisteredOrganization>
            <ComputerName>*</ComputerName>
        </component>
        <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <RunSynchronous>
                <RunSynchronousCommand wcm:action="add">
                    <Order>1</Order>
                    <Path>reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" /v ShippedWithReserves /t REG_DWORD /d 0 /f</Path>
                    <Description>Disable reserved storage for Windows 10 1903 and later...</Description>
                </RunSynchronousCommand>
            </RunSynchronous>
        </component>
    </settings>
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <InputLocale>zh-TW</InputLocale>
            <SystemLocale>zh-TW</SystemLocale>
            <UILanguage>zh-TW</UILanguage>
            <UserLocale>zh-TW</UserLocale>
        </component>
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <UserAccounts>
                <LocalAccounts>
                    <LocalAccount wcm:action="add">
                        <Password>
                            <Value>cABhAHMAcwB3AG8AcgBkAFAAYQBzAHMAdwBvAHIAZAA=</Value>
                            <PlainText>false</PlainText>
                        </Password>
                        <Description>Administrative User</Description>
                        <DisplayName>admin</DisplayName>
                        <Group>Administrators</Group>
                        <Name>admin</Name>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <OOBE>
                <ProtectYourPC>3</ProtectYourPC>
            </OOBE>
            <AutoLogon>
                <Username>admin</Username>
                <Password>
                    <Value>cABhAHMAcwB3AG8AcgBkAFAAYQBzAHMAdwBvAHIAZAA=</Value>
                    <PlainText>false</PlainText>
                </Password>
                <Enabled>true</Enabled>
                <LogonCount>1</LogonCount>
            </AutoLogon>
            <FirstLogonCommands>
                <SynchronousCommand wcm:action="add">
                    <Order>1</Order>
                    <Description>Set Default Input Mode to Alphanumeric...</Description>
                    <CommandLine>reg add "HKCU\SOFTWARE\Microsoft\IME\15.0\IMETC" /v "Default Input Mode" /t REG_SZ /d "0x00000001" /f</CommandLine>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <Order>2</Order>
                    <Description>Post installation...</Description>
                    <CommandLine>cmd /c %WINDIR%\Setup\Scripts\MyPost.cmd</CommandLine>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <Order>3</Order>
                    <Description>Reboot...</Description>
                    <CommandLine>cmd /c Shutdown -r -f -t 180</CommandLine>
                </SynchronousCommand>
            </FirstLogonCommands>
        </component>
    </settings>
</unattend>


檔案2. MyPost.cmd
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@echo off
REM ###########################################################
REM #  By Proliantaholic https://proliantaholic.blogspot.com  #
REM ###########################################################

Echo Turn off SMB 1.0/CIFS File Sharing Support...
powershell -Command "Disable-WindowsOptionalFeature -Online -FeatureName smb1protocol -NoRestart >$null 2>&1"
Echo Done.
Echo.

REM Timeout in seconds
set /A timeout=100

CHOICE /T %timeout% /C YN /D N /M "Change Computer Name? (will be skipped in %timeout% seconds)"
if %ERRORLEVEL%==2 Echo Skipped&goto :RenCompNameDone
powershell -ExecutionPolicy Unrestricted -File %WINDIR%\Setup\Scripts\RenCompName.ps1
control /name microsoft.system
:RenCompNameDone
Echo Done.
pause

cd /d %~dp0
attrib -R -A -S -H *.*
RMDIR /S /Q %Systemroot%\Setup\Scripts


檔案3. RenCompName.ps1
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
###########################################################
#  By Proliantaholic https://proliantaholic.blogspot.com  #
###########################################################

Write-Host "目前電腦名稱:" $env:computername
$NewComputerName = Read-Host -Prompt "輸入新的電腦名稱"
$go = Read-Host -Prompt "確定要更改電腦名稱? (Y/N)"
if (($go -eq "Y") -or ($go -eq "y")) {
    Rename-Computer -NewName $NewComputerName -PassThru
}

以上檔案使用Windows 10(版本 1909/19H2)繁體中文專業版安裝測試過
怕檔案編碼會搞錯的: 請按此下載


後記:
  • 個人認為使用自動安裝回應檔案的目的, 主要是希望能不要人為介入(輸入)就能自動裝完, 請依據實際狀況彈性調整回應檔跟批次處理的寫法.
  •  <AutoLogon><LogonCount>有個已知的問題, 就是會多AutoLogon一次. Windows 10才有此問題, Windows Server 2016/2019並不會多自動登入一次. 所以此篇的回應檔寫法, 雖然LogonCount為1, 在更改電腦名稱重啟後, 還是會再多自動登入到桌面一次(不用另外鍵入密碼). 要避免多自動登入一次的方法請參考: LogonCount


繼續閱讀:
PART Max 懶人包

2020年4月6日

P8 如何用 Windows系統映像管理員(Windows System Image Manager) 製作Windows 10自動安裝回應檔案
PART VIII 指定電腦名稱與加入網域


PART I 準備工作
PART II 瞭解Windows 10安裝過程
PART III 製作自動安裝回應檔案
PART IV 如何使用
PART V 關閉[SMB 1.0/CIFS 檔案共用支援]功能
PART VI 使用DiskPart建立磁碟分割
PART VII 不要預留[保留的儲存空間]
PART VIII 指定電腦名稱與加入網域
PART IX 彈性搭配批次檔使用
PART Max 懶人包

指定電腦名稱
電腦名稱可以在兩個階段指定(擇一使用):

windowsPE階段

specialize階段

(接下來用 specialize階段 的方式舉例)

1
2
3
4
5
6
7
8
9
<settings pass="specialize">
    <!-- 其他component -->
    <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="NonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <RegisteredOwner>ABC</RegisteredOwner>
        <RegisteredOrganization>IT</RegisteredOrganization>
        <ComputerName>*</ComputerName>
    </component>
    <!-- 其他component -->
</settings>

  • 如果在自動安裝回應檔案中未指定ComputerName, Windows會隨機產生電腦名稱
  • 如果ComputerName設為自訂名稱(最多15個字元), 例如: MYPCNAME. 那每次透過此自動安裝回應檔案安裝的Windows電腦名稱都會是MYPCNAME, 不過電腦名稱都一樣的話容易導致衝突
  • 如果ComputerName設為星號 * 或是空字串, Windows會根據以下的規則順序組成一個15個字元的電腦名稱:
    1. 用RegisteredOwner加上RegisteredOrganization (最多取前面7個字元, 多的部分會截掉)
    2. 加上一個連字號 -
    3. 加上隨機字元補滿15個字元
以下為幾個電腦名稱的例子: (X表示為隨機產生的字元)

RegisteredOwner: ABC
RegisteredOrganization: IT
電腦名稱: ABCIT-XXXXXXXXX

RegisteredOwner: IT
電腦名稱: IT-XXXXXXXXXXXX

RegisteredOrganization: IT
電腦名稱: WINDOWS-XXXXXXX
(沒指定RegisteredOwner只指定RegisteredOrganization, 電腦名稱會變成WINDOWS開頭)

RegisteredOwner: ABCDE
RegisteredOrganization: 12345
電腦名稱: ABCDE12-XXXXXXX

RegisteredOwner: ABCDEFGHI
RegisteredOrganization: 12345
電腦名稱: ABCDEFG-XXXXXXX






注意:
根據 隱藏回應檔案中的機密資料 的說明

Windows系統映像管理員 (Windows SIM) 可以設定隱藏回應檔案中的密碼包括下列各項:
  • Microsoft-Windows-Shell-Setup | AutoLogon | Password
  • Microsoft-Windows-Shell-Setup | UserAccounts | AdministratorPassword
  • Microsoft-Windows-Shell-Setup | UserAccounts | LocalAccounts | LocalAccount | Password
並未包含加入網域會使用到的:
  • Microsoft-Windows-UnattendedJoin | Identification | Credentials | Password
加入網域
specialize階段
下列方法請斟酌使用, 建議用最小權限的帳戶來進行:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<settings pass="specialize">
    <!-- 其他component -->
        <component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="NonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <Identification>
               <Credentials>
                  <Domain>proliantaholic.lab</Domain>
                  <Password>minPassword</Password>
                  <Username>minUser</Username>
               </Credentials>
               <JoinDomain>proliantaholic.lab</JoinDomain>
            </Identification>
        </component>
    <!-- 其他component -->
</settings>


繼續閱讀:
PART IX 彈性搭配批次檔使用

版權宣告

Creative Commons License
本著作由 PROLIANTAHOLIC 製作,以創用CC 姓名標示-非商業性-禁止改作 3.0 台灣 授權條款釋出。
文內所述之產品和公司名稱均為其各自擁有者的商標及(或)服務標記。