免互動安裝D2、解除安裝,以及在部署工具中偵測安裝狀態所用的指令。只列出確定可用的指令:來自資訊清單,或是安裝程式技術的官方預設參數。
相關教學: 靜默安裝參數總整理:MSI、NSIS、Inno Setup · 用登錄檔或PowerShell解除安裝程式
使用winget
PowerShell
winget install --id Terrastruct.D2 -e --silent --accept-package-agreements --accept-source-agreementswinget upgrade --id Terrastruct.D2 -e --silentwinget uninstall --id Terrastruct.D2 -e --silent依安裝檔
64位元 · MSI · 所有使用者
靜默安裝
msiexec /i d2-v0.9.0-windows-amd64.msi /qn /norestart寫入記錄檔
msiexec /i d2-v0.9.0-windows-amd64.msi /qn /norestart /l*v "%TEMP%\d2-install.log"解除安裝
msiexec /x {91D48A67-5FAB-47CF-AB12-A2E1F1399B4C} /qn /norestart- MSI產品代碼
- {91D48A67-5FAB-47CF-AB12-A2E1F1399B4C}
- 解除安裝登錄機碼
- HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{91D48A67-5FAB-47CF-AB12-A2E1F1399B4C}
- UpgradeCode
- {AC84FEE7-EB67-4F5D-A08D-ADEF69538690}
- 安裝資料夾
- %ProgramFiles%/D2
PowerShell:下載、驗證、安裝
下載官方檔案,驗證SHA256後靜默安裝。
install-d2.ps1
$url = 'https://github.com/d2lang/d2/releases/download/v0.9.0/d2-v0.9.0-windows-amd64.msi'
$sha256 = 'DBAC13EDAEC26878D36C79C2BCD91D57927CAE8878204E3B9816E6C0F32AAE1B'
$file = Join-Path $env:TEMP 'd2-v0.9.0-windows-amd64.msi'
Invoke-WebRequest -Uri $url -OutFile $file -UseBasicParsing
if ((Get-FileHash $file -Algorithm SHA256).Hash -ne $sha256) { throw 'SHA256 mismatch' }
Start-Process msiexec.exe -ArgumentList '/i', ('"{0}"' -f $file), '/qn', '/norestart' -Wait