-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-webview2.ps1
More file actions
233 lines (189 loc) · 7.19 KB
/
install-webview2.ps1
File metadata and controls
233 lines (189 loc) · 7.19 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Installs Microsoft Edge WebView2 Runtime on Windows Server 2016 and later.
.DESCRIPTION
This script downloads and installs the Microsoft Edge WebView2 Runtime,
which is required for the SQLTriage application to run.
Supports:
- Windows Server 2016 (Version 1607)
- Windows Server 2019
- Windows Server 2022
- Windows 10/11
.PARAMETER Silent
If specified, runs the installer in silent mode without user interaction.
.PARAMETER Force
If specified, reinstalls WebView2 even if it's already installed.
.EXAMPLE
.\install-webview2.ps1
.EXAMPLE
.\install-webview2.ps1 -Silent
.EXAMPLE
.\install-webview2.ps1 -Silent -Force
.NOTES
Author: SQLTriage Team
Version: 1.0.0
Required OS: Windows Server 2016 or later, Windows 10 1809 or later
#>
[CmdletBinding()]
param(
[switch]$Silent,
[switch]$Force
)
$ErrorActionPreference = "Stop"
# WebView2 Evergreen Runtime download URL
$WebView2DownloadUrl = "https://go.microsoft.com/fwlink/p/?LinkId=2124703"
$InstallerPath = Join-Path $env:TEMP "WebView2Installer.exe"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " WebView2 Runtime Installer" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Check if WebView2 is already installed
function Test-WebView2Installed {
try {
$webView2Path = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"
if (Test-Path $webView2Path) {
$version = (Get-ItemProperty -Path $webView2Path -Name "pv" -ErrorAction SilentlyContinue).pv
if ($version) {
return @{
Installed = $true
Version = $version
}
}
}
# Check 64-bit registry location
$webView2Path64 = "HKLM:\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"
if (Test-Path $webView2Path64) {
$version = (Get-ItemProperty -Path $webView2Path64 -Name "pv" -ErrorAction SilentlyContinue).pv
if ($version) {
return @{
Installed = $true
Version = $version
}
}
}
return @{
Installed = $false
Version = $null
}
}
catch {
return @{
Installed = $false
Version = $null
}
}
}
# Check Windows version
function Test-WindowsVersion {
$os = Get-CimInstance -ClassName Win32_OperatingSystem
$version = [System.Version]$os.Version
Write-Host "Operating System: $($os.Caption)" -ForegroundColor Gray
Write-Host "Version: $($os.Version)" -ForegroundColor Gray
Write-Host "Architecture: $($os.OSArchitecture)" -ForegroundColor Gray
Write-Host ""
# Windows Server 2016 is version 10.0.14393
if ($version.Major -eq 10 -and $version.Build -ge 14393) {
return $true
}
# Windows 10 1809 is version 10.0.17763
if ($version.Major -eq 10 -and $version.Build -ge 17763) {
return $true
}
# Windows 11
if ($version.Major -ge 10 -and $version.Build -ge 22000) {
return $true
}
return $false
}
# Main execution
Write-Host "Checking system requirements..." -ForegroundColor Yellow
if (-not (Test-WindowsVersion)) {
Write-Host "ERROR: This system does not meet the minimum requirements." -ForegroundColor Red
Write-Host "Windows Server 2016 (Version 1607) or later is required." -ForegroundColor Red
exit 1
}
Write-Host "Checking for existing WebView2 installation..." -ForegroundColor Yellow
$existingInstall = Test-WebView2Installed
if ($existingInstall.Installed -and -not $Force) {
Write-Host "WebView2 Runtime is already installed!" -ForegroundColor Green
Write-Host "Version: $($existingInstall.Version)" -ForegroundColor Green
Write-Host ""
Write-Host "Use -Force parameter to reinstall." -ForegroundColor Gray
exit 0
}
if ($existingInstall.Installed -and $Force) {
Write-Host "Reinstalling WebView2 Runtime (version: $($existingInstall.Version))..." -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Downloading WebView2 Runtime..." -ForegroundColor Yellow
try {
# Download the installer
$ProgressPreference = 'SilentlyContinue' # Faster download
Invoke-WebRequest -Uri $WebView2DownloadUrl -OutFile $InstallerPath -UseBasicParsing
if (-not (Test-Path $InstallerPath)) {
throw "Download failed - file not found"
}
$fileSize = (Get-Item $InstallerPath).Length / 1MB
Write-Host "Downloaded: $InstallerPath ($([math]::Round($fileSize, 2)) MB)" -ForegroundColor Green
}
catch {
Write-Host "ERROR: Failed to download WebView2 Runtime: $_" -ForegroundColor Red
# Try alternative download method
Write-Host ""
Write-Host "Trying alternative download method..." -ForegroundColor Yellow
try {
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($WebView2DownloadUrl, $InstallerPath)
if (Test-Path $InstallerPath) {
$fileSize = (Get-Item $InstallerPath).Length / 1MB
Write-Host "Downloaded: $InstallerPath ($([math]::Round($fileSize, 2)) MB)" -ForegroundColor Green
}
}
catch {
Write-Host "ERROR: Alternative download also failed: $_" -ForegroundColor Red
Write-Host ""
Write-Host "Please manually download WebView2 Runtime from:" -ForegroundColor Yellow
Write-Host "https://developer.microsoft.com/en-us/microsoft-edge/webview2/" -ForegroundColor Cyan
exit 1
}
}
Write-Host ""
Write-Host "Installing WebView2 Runtime..." -ForegroundColor Yellow
try {
$installArgs = "/silent /install"
if ($Silent) {
$installArgs = "/silent /install"
}
$process = Start-Process -FilePath $InstallerPath -ArgumentList $installArgs -Wait -PassThru
# Clean up installer
Remove-Item $InstallerPath -Force -ErrorAction SilentlyContinue
if ($process.ExitCode -eq 0) {
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host " Installation Successful!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
# Verify installation
Start-Sleep -Seconds 2
$newInstall = Test-WebView2Installed
if ($newInstall.Installed) {
Write-Host "WebView2 Runtime Version: $($newInstall.Version)" -ForegroundColor Green
}
Write-Host ""
Write-Host "You can now run the SQLTriage application." -ForegroundColor Cyan
exit 0
}
else {
Write-Host "ERROR: Installation failed with exit code $($process.ExitCode)" -ForegroundColor Red
exit $process.ExitCode
}
}
catch {
Write-Host "ERROR: Installation failed: $_" -ForegroundColor Red
# Clean up on error
if (Test-Path $InstallerPath) {
Remove-Item $InstallerPath -Force -ErrorAction SilentlyContinue
}
exit 1
}