From: 011netservice@gmail.com Date: 2025-06-08 Subject: Chocolatey.txt https://svc.011.idv.tw/CodeHelper/Windows/Chocolatey.txt 歡迎來信交流, 訂購軟體需求. Chocolatey 是 Windows 作業系統的套件管理工具,類似於 Linux 上的 apt 或 yum。 可以透過命令列輕鬆地安裝、更新、設定和移除軟體。 - 自動化安裝: 只需一行指令即可安裝應用程式(例如:`choco install googlechrome`)。 - 集中管理: 可以統一管理所有安裝的應用程式與工具。 - 支援 GUI 與 CLI: 除了命令列,也有圖形化介面(Chocolatey GUI)。 - 廣泛的套件庫: 擁有數千個常用應用程式的套件(如 Chrome、VS Code、Node.js、Git 等)。 安裝 Chocolatey(在 Windows 上) 1. 以系統管理員身份開啟 PowerShell。 2. 執行以下指令: Set-ExecutionPolicy Bypass -Scope Process -Force; ` [System.Net.ServicePointManager]::SecurityProtocol = ` [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; ` iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) 常見指令 安裝套件: choco install <套件名稱> 升級套件: choco upgrade <套件名稱> 移除套件: choco uninstall <套件名稱> 搜尋套件: choco search <關鍵字> 查看已安裝: choco list --local-only - 系統管理員快速部署多台電腦的軟體。 - 開發者建立自動化開發環境。 - 使用者快速安裝常用工具而不需手動下載安裝檔。 #### 查詢可安裝的軟體: Chocolatey packges, 20250608 https://community.chocolatey.org/packages 常見指令 安裝套件: choco install <套件名稱> 升級套件: choco upgrade <套件名稱> 移除套件: choco uninstall <套件名稱> 搜尋套件: choco search <關鍵字> 查看已安裝: choco list --local-only #### 安裝方式1: command Install with cmd.exe Run the following command: @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" #### 安裝方式2: PowerShell Install with PowerShell.exe With PowerShell, there is an additional step. You must ensure Get-ExecutionPolicy is not Restricted. We suggest using Bypass to bypass the policy to get things installed or AllSigned for quite a bit more security. 1. 執行 Get-ExecutionPolicy 後, 若回傳 Restricted, 則再 Set-ExecutionPolicy Bypass -Scope Process. Run Get-ExecutionPolicy. If it returns Restricted, then run Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass -Scope Process. (目前 PowerShell 工作階段中有效) 2. 執行遠端 install.ps1 的腳本. Now run the following command: Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) 說明: 1. Unrestricted(不受限制) PowerShell 允許執行所有腳本,不論是本機還是從網路下載的。 從網路下載的腳本在第一次執行時會顯示一個安全警告(提示你是否確定要執行),但不會阻止執行。 這是最寬鬆的執行政策,風險較高,因為惡意腳本也可能被執行。 如果你不是在開發或測試環境中,建議不要長期使用 Unrestricted。可以考慮改為: RemoteSigned:允許執行本機腳本,但從網路下載的腳本必須有有效的簽章。 AllSigned:所有腳本都必須有簽章。 Restricted:不允許執行任何腳本(預設值)。 2. 以下兩個指令的差異為何 ? Set-ExecutionPolicy AllSigned Set-ExecutionPolicy Bypass -Scope Process. 差異主要在於 執行政策的嚴格程度 和 作用範圍(Scope) Set-ExecutionPolicy AllSigned 說明:只允許執行由受信任的發行者簽署的腳本。 安全性:非常高。即使是本機腳本也必須簽署才能執行。 適用場景:企業環境、需要嚴格控制腳本來源的情境。 預設作用範圍:如果未指定 -Scope,則預設為 LocalMachine,會影響所有使用者。 Set-ExecutionPolicy Bypass -Scope Process 說明:完全繞過執行政策的限制,允許執行任何腳本。 安全性:非常低。適合暫時性需求,例如測試或執行不受信任來源的腳本。 作用範圍:-Scope Process 表示只在目前 PowerShell 工作階段中有效,關閉視窗後即失效,不會影響系統其他部分。 #### 其他注意事項 Additional considerations NOTE Please inspect https://community.chocolatey.org/install.ps1 prior to running any of these scripts to ensure safety. We already know it’s safe, but you should verify the security and contents of any script from the internet you are not familiar with. All of these scripts download a remote PowerShell script and execute it on your machine. We take security very seriously. Learn more. “Why do I need to enable TLS 1.2 in PowerShell? Shouldn’t it be on by default when I load PowerShell?” Unfortunately it’s not always a default, and more of the time it is not. The low level is that it depends on .NET Framework and Windows. Explicitly set - Basically you need .NET Fx 4.5 at a minimum to be able to explicitly set TLS 1.2. Load by default - To have it load by default when you run PowerShell, you need at least .NET Fx 4.7 AND the Operating System’s SystemDefault to have TLS 1.2 enabled. The load by default is really hard to see, so you should check to ensure it is there. Assume it doesn’t and set explicitly. 在執行任何這些指令碼之前,請先檢查 https://community.chocolatey.org/install.ps1 以確保其安全性。 我們已經知道它是安全的,但你仍應該自行驗證從網路上取得的任何指令碼的安全性與內容,特別是當你對它不熟悉時。 這些指令碼都會下載遠端的 PowerShell 指令碼並在你的電腦上執行。 我們非常重視安全性。了解更多資訊。 「為什麼我需要在 PowerShell 中啟用 TLS 1.2?載入 PowerShell 時不是應該預設啟用嗎?」 不幸的是,它並不總是預設啟用,而且大多數情況下都不是。 根本原因在於它依賴於 .NET Framework 和 Windows 的設定。 明確設定:基本上你需要至少 .NET Framework 4.5 才能夠明確設定使用 TLS 1.2。 預設載入:若要在執行 PowerShell 時自動預設載入 TLS 1.2,你需要至少 .NET Framework 4.7,而且作業系統的 SystemDefault 必須啟用 TLS 1.2。 預設載入的狀態很難察覺,因此你應該主動檢查是否已啟用。 建議假設它沒有啟用,並手動明確設定。 #### 以 Chocolatey 安裝軟體 安全程度如何 ? 使用 Chocolatey 安裝軟體在多數情況下是**相對安全的**,但仍有一些風險與注意事項。以下是對其安全性的分析: --- ### ✅ **安全優點** 1. **開源與社群維護**: - Chocolatey 是開源的,社群活躍,許多套件由信譽良好的開發者或組織維護。 - 官方維護的套件(如 `chocolatey-core.extension`)通常更可靠。 2. **自動化與一致性**: - 使用 Chocolatey 可以避免手動下載與安裝,減少人為錯誤與惡意網站風險。 3. **套件審核機制**: - Chocolatey.org 上的套件會經過自動與人工審核流程,檢查是否有惡意行為或錯誤。 4. **支援企業級安全**(付費版): - Chocolatey for Business 提供更嚴格的安全控制、內部套件倉庫與審核流程。 --- ### ⚠️ **潛在風險** 1. **第三方套件來源不一**: - 並非所有套件都由官方維護,有些可能來自不明開發者,風險較高。 2. **套件更新延遲**: - 有些套件更新不及時,可能導致使用過時或有漏洞的版本。 3. **執行權限問題**: - 安裝過程通常需要管理員權限,若套件中含有惡意腳本,可能造成系統風險。 4. **缺乏沙箱機制**: - Chocolatey 安裝的是原生應用程式,並非沙箱環境,無法完全隔離風險。 --- ### 🔐 **安全使用建議** - **只安裝來自信任來源的套件**(查看套件頁面上的維護者與下載數)。 - **定期更新 Chocolatey 與套件**,以獲得最新安全修補。 - **使用防毒軟體與系統還原點**,以防萬一。 - **企業用戶可考慮使用私有倉庫與審核流程**。 ---