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)內容主要來自:
透過批次檔(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.autounattend.xml複製到Windows 10安裝媒體/(ISO檔案裡)的 根目錄
- 把檔案2.MyPost.cmd和檔案3.RenCompName.ps1複製到Windows 10安裝媒體/(ISO檔案裡)的 sources\$OEM$\$$\Setup\Scripts
- 因為檔案3.內有中文字元, 檔案編碼需要是UTF-16 LE/UCS-2 LE BOM顯示才不會亂碼
- 使用該安裝媒體安裝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 懶人包