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 台灣 授權條款釋出。
文內所述之產品和公司名稱均為其各自擁有者的商標及(或)服務標記。