-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathmain.ps1
More file actions
275 lines (262 loc) · 10.5 KB
/
main.ps1
File metadata and controls
275 lines (262 loc) · 10.5 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#Requires -RunAsAdministrator
#Requires -Version 4.0
# GitHub requires TLS v1.2, but it's not enabled by default in PowerShell v5.0 and older releases
[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
$OS = Get-CimInstance Win32_OperatingSystem
$BaseURL = "https://raw.githubusercontent.com/corbindavenport/just-the-browser/main/"
$MicrosoftEdgeInstallRegistry = "$BaseURL/edge/install.reg"
$MicrosoftEdgeUninstallRegistry = "$BaseURL/edge/uninstall.reg"
$GoogleChromeInstallRegistry = "$BaseURL/chrome/install.reg"
$GoogleChromeUninstallRegistry = "$BaseURL/chrome/uninstall.reg"
$FirefoxInstallRegistry = "$BaseURL/firefox/install.reg"
$FirefoxUninstallRegistry = "$BaseURL/firefox/uninstall.reg"
# Render initial interface for all pages
function Show-Header {
Clear-Host
Write-Host "`nJust the Browser ($($OS.Caption) Build $($OS.BuildNumber))`n========`n"
}
# Remove Firefox JSON file if it exists, so it does not conflict with registry entries
# Previous versions of Just the Browser used the JSON method
function Uninstall-FirefoxJSON {
Param(
[Parameter(Position = 0, Mandatory = $true)]
[String]$InstallPath
)
if (Test-Path "$InstallPath\distribution\policies.json") {
Write-Host "Previous Firefox policies.json file found, deleting..."
Remove-Item -Path "$InstallPath\distribution\policies.json" -Force
}
}
# Install Google Chrome settings
function Install-Chrome {
Show-Header
Write-Host "Downloading registry file, please wait..."
# Download file
try {
Invoke-WebRequest $GoogleChromeInstallRegistry -OutFile "$env:LocalAppData\chrome.reg"
}
catch {
Read-Host -Prompt "Download failed! Press Enter/Return to continue" | Out-Null
Return
}
# Install file
$ChromeInstall = Start-Process "reg.exe" -ArgumentList "import `"$env:LocalAppData\chrome.reg`"" -WindowStyle Hidden -Wait -PassThru
if ($ChromeInstall.ExitCode -eq 0) {
Read-Host -Prompt "Updated Google Chrome settings. Press Enter/Return to continue" | Out-Null
}
else {
Read-Host -Prompt "Install failed! Press Enter/Return to continue" | Out-Null
}
}
# Remove Google Chrome settings
function Uninstall-Chrome {
Show-Header
Write-Host "Downloading registry file, please wait..."
# Download file
try {
Invoke-WebRequest $GoogleChromeUninstallRegistry -OutFile "$env:LocalAppData\chrome.reg"
}
catch {
Read-Host -Prompt "Download failed! Press Enter/Return to continue" | Out-Null
Return
}
# Install file
$ChromeUninstall = Start-Process "reg.exe" -ArgumentList "import `"$env:LocalAppData\chrome.reg`"" -WindowStyle Hidden -Wait -PassThru
if ($ChromeUninstall.ExitCode -eq 0) {
Read-Host -Prompt "Removed Google Chrome settings. Press Enter/Return to continue" | Out-Null
}
else {
Read-Host -Prompt "Remove failed! Press Enter/Return to continue" | Out-Null
}
}
# Install Microsoft Edge settings
function Install-Edge {
Show-Header
Write-Host "Downloading registry file, please wait..."
# Download file
try {
Invoke-WebRequest $MicrosoftEdgeInstallRegistry -OutFile "$env:LocalAppData\edge.reg"
}
catch {
Read-Host -Prompt "Download failed! Press Enter/Return to continue" | Out-Null
Return
}
# Install file
$EdgeInstall = Start-Process "reg.exe" -ArgumentList "import `"$env:LocalAppData\edge.reg`"" -WindowStyle Hidden -Wait -PassThru
if ($EdgeInstall.ExitCode -eq 0) {
Read-Host -Prompt "Updated Microsoft Edge settings. Press Enter/Return to continue" | Out-Null
}
else {
Read-Host -Prompt "Install failed! Press Enter/Return to continue" | Out-Null
}
}
# Remove Microsoft Edge settings
function Uninstall-Edge {
Show-Header
Write-Host "Downloading registry file, please wait..."
# Download file
try {
Invoke-WebRequest $MicrosoftEdgeUninstallRegistry -OutFile "$env:LocalAppData\edge.reg"
}
catch {
Read-Host -Prompt "Download failed! Press Enter/Return to continue" | Out-Null
Return
}
# Install file
$EdgeUninstall = Start-Process "reg.exe" -ArgumentList "import `"$env:LocalAppData\edge.reg`"" -WindowStyle Hidden -Wait -PassThru
if ($EdgeUninstall.ExitCode -eq 0) {
Read-Host -Prompt "Removed Microsoft Edge settings. Press Enter/Return to continue" | Out-Null
}
else {
Read-Host -Prompt "Remove failed! Press Enter/Return to continue" | Out-Null
}
}
# Install Firefox settings
function Install-Firefox {
Param(
[Parameter(Position = 0)]
[String]$InstallPath
)
Show-Header
# Delete old JSON configuration if the Firefox registry path was found, and if the JSON file exists
if ($InstallPath) {
Uninstall-FirefoxJSON "$InstallPath"
}
# Download file
Write-Host "Downloading registry file, please wait..."
try {
Invoke-WebRequest $FirefoxInstallRegistry -OutFile "$env:LocalAppData\firefox.reg"
}
catch {
Read-Host -Prompt "Download failed! Press Enter/Return to continue" | Out-Null
Return
}
# Install file
$FirefoxInstall = Start-Process "reg.exe" -ArgumentList "import `"$env:LocalAppData\firefox.reg`"" -WindowStyle Hidden -Wait -PassThru
if ($FirefoxInstall.ExitCode -eq 0) {
Read-Host -Prompt "Updated Mozilla Firefox settings. Press Enter/Return to continue" | Out-Null
}
else {
Read-Host -Prompt "Install failed! Press Enter/Return to continue" | Out-Null
}
}
# Remove Firefox settings
function Uninstall-Firefox {
Param(
[Parameter(Position = 0)]
[String]$InstallPath
)
Show-Header
# Delete old JSON configuration if the Firefox registry path was found, and if the JSON file exists
if ($InstallPath) {
Uninstall-FirefoxJSON "$InstallPath"
}
# Download file
try {
Invoke-WebRequest $FirefoxUninstallRegistry -OutFile "$env:LocalAppData\firefox.reg"
}
catch {
Read-Host -Prompt "Download failed! Press Enter/Return to continue" | Out-Null
Return
}
# Install file
$FirefoxUninstall = Start-Process "reg.exe" -ArgumentList "import `"$env:LocalAppData\firefox.reg`"" -WindowStyle Hidden -Wait -PassThru
if ($FirefoxUninstall.ExitCode -eq 0) {
Read-Host -Prompt "Removed Mozilla Firefox settings. Press Enter/Return to continue" | Out-Null
}
else {
Read-Host -Prompt "Remove failed! Press Enter/Return to continue" | Out-Null
}
}
# Main menu selection
function Show-Menu {
# Create list for menu options
$options = New-Object System.Collections.Generic.List[psobject]
# Google Chrome without settings applied
$options.Add(@{
Label = "Google Chrome: Update settings"
Action = { Install-Chrome }
})
# Google Chrome with settings applied
if (Test-Path "HKLM:\SOFTWARE\Policies\Google\Chrome") {
$GoogleChromeCheck = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Google\Chrome" -ErrorAction SilentlyContinue).AIModeSettings
if ($null -ne $GoogleChromeCheck) {
$options.Add(@{
Label = "Google Chrome: Remove settings"
Action = { Uninstall-Chrome }
})
}
}
# Microsoft Edge without settings applied
$options.Add(@{
Label = "Microsoft Edge: Update settings"
Action = { Install-Edge }
})
# Microsoft Edge with settings applied
if (Test-Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge") {
$MicrosoftEdgeCheck = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -ErrorAction SilentlyContinue).HideFirstRunExperience
if ($null -ne $MicrosoftEdgeCheck) {
$options.Add(@{
Label = "Microsoft Edge: Remove settings"
Action = { Uninstall-Edge }
})
}
}
# Mozilla Firefox
if (Test-Path "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox") {
# Find the current version installed, like: 147.0.1 (AArch64 en-US)
$FirefoxVersion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox" -ErrorAction SilentlyContinue).CurrentVersion
# Find the registry values for the specified version
if (Test-Path "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox\$FirefoxVersion\Main") {
# Finds the installation path, like: C:\Program Files\Mozilla Firefox
$FirefoxPath = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox\$FirefoxVersion\Main" -ErrorAction SilentlyContinue)."Install Directory"
# Firefox without settings alreay applied
$options.Add(@{
Label = "Mozilla Firefox: Update settings"
Action = { Install-Firefox "$FirefoxPath" }
})
# Firefox with settings already applied
# This script previously used the JSON file for Firefox, so that must be checked in addition to the registry method
if ((Test-Path "$FirefoxPath\distribution\policies.json") -or (Test-Path "HKLM:\SOFTWARE\Policies\Mozilla\Firefox\FirefoxHome")) {
$options.Add(@{
Label = "Mozilla Firefox: Remove settings"
Action = { Uninstall-Firefox "$FirefoxPath" }
})
}
}
else {
$options.Add(@{
Label = "Mozilla Firefox: Update settings"
Action = { Install-Firefox }
})
if (Test-Path "HKLM:\SOFTWARE\Policies\Mozilla\Firefox\FirefoxHome") {
$options.Add(@{
Label = "Mozilla Firefox: Remove settings"
Action = { Uninstall-Firefox }
})
}
}
}
# Exit option
$options.Add(@{
Label = "Exit"; Action = { exit }
})
# Show main menu
Show-Header
Write-Host "Select an option by typing the number, then pressing Return/Enter on your keyboard to confirm.`n`nYou will need to restart your browser for changes to take effect.`n"
for ($i = 0; $i -lt $options.Count; $i++) {
Write-Host "[$($i + 1)] $($options[$i].Label)"
}
$selection = Read-Host "`n#"
# Process menu selections
if ($selection -match '^\d+$' -and $selection -le $options.Count) {
$index = [int]$selection - 1
& $options[$index].Action
# Return to main menu after complete
Show-Menu
}
else {
Show-Menu
}
}
Show-Menu