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 彈性搭配批次檔使用

2020年3月15日

[Rainmeter面板] MaskInfo 健保特約機構口罩剩餘數量資訊

寫了個用來顯示健保特約機構口罩剩餘數量資訊的Rainmeter面板(skin).

有興趣的請到這裡下載使用:

使用說明:

安裝

  • 下載 然後使用 Rainmeter 的 SkinInstaller.exe 安裝

設定

指定醫事機構代碼(NhiCode):
  • 在 Settings.txt 內設定. (在 MaskInfo\@RESOURCES\Settings 目錄內)
  • 也可以在面板上按右鍵 -> 自訂面板動作 -> 手動設定醫事機構代碼及其他參數 (會打開 Settings.txt)
  • 醫事機構代碼可參考: 健保特約機構口罩剩餘數量明細清單 醫事機構代碼欄位. 例如: 2101150012 (士林健康服務中心)
用滑鼠右鍵單擊不同區域可以變更設定: (輸入代碼後請按Enter確定變更)
  • 代碼 XXXXXXXXXX: 設定要顯示口罩剩餘數量資訊的 醫事機構代碼
  • 來源資料時間/每X分鐘更新文字: 設定 資料更新頻率 (分鐘)
  • 常用機構1/常用機構2/常用機構3: 設定常用的 醫事機構代碼 (3組可供滑鼠左鍵雙擊切換使用)

使用

用滑鼠左鍵雙擊不同區域可以帶出不同資訊:
  • 醫事機構名稱: 開啟該醫事機構在 藥局口罩採購地圖 (江明宗先生製作) 的網頁
  • 醫事機構地址: 開啟該地址的GoogleGoogle Maps網頁
  • 常用機構1/常用機構2/常用機構3: 切換 醫事機構代碼 為設定的常用代碼, 並更新面板資訊
將滑鼠指標移至不同區域可以顯示不同資訊:
  • 常用機構文字: 顯示該醫事機構口罩剩餘數量資訊

教學影片


資料來源與授權

版權宣告

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