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)下執行

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

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

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


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


打開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年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安裝應用程式的選擇, (winget仍為preview版本, 請斟酌使用)

有安裝測試過的版本:
Windows 10 專業版 (繁體中文) 64位元版
  • 版本 2004/20H1
  • 版本 1909/19H2
  • 版本 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 檔案共用支援]功能
  • 修改使用者跟預設的註冊機碼
    • Turn off [Start OneDrive automatically when sign in to Windows]
    • Show Search icon (instead of box)
    • Hide Cortana button
    • Show This PC icon
    • Show Network icon
    • Show Control Panel icon
    • Show File name extensions
    • UAC Do not dim my deskyop
    • Set AutoLogonCount to 0
    • Set Default Input Mode to Alphanumeric
    • 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
    • RenCompName.ps1: 更改電腦名稱 
    注意: DnInWinget.ps1 DnInWinTerminal.ps1 會透過 https://store.rg-adguard.net 查詢package的下載連結(package檔案是從微軟網站下載), 如有顧慮就請不要使用
  • 刪除%Systemroot%\Setup\Scripts裡面的所有檔案

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


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


版權宣告

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