mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-24 03:45:30 +00:00
Pull Request (#2526)
* Update edgeremoval.ps1 * Update edgeremoval.ps1 * Update edgeremoval.ps1
This commit is contained in:
parent
1c9cef0079
commit
de8a79df22
386
edgeremoval.ps1
386
edgeremoval.ps1
@ -1,195 +1,28 @@
|
||||
# Script Metadata
|
||||
# Created by AveYo, source: https://raw.githubusercontent.com/AveYo/fox/main/Edge_Removal.bat
|
||||
# Powershell Conversion and Refactor done by Chris Titus Tech
|
||||
|
||||
# Initial Configuration
|
||||
$host.ui.RawUI.WindowTitle = 'Edge Removal - Chris Titus Tech 2023.05.10'
|
||||
$remove_win32 = @("Microsoft Edge", "Microsoft Edge Update")
|
||||
$remove_appx = @("MicrosoftEdge")
|
||||
$skip = @() # Optional: @("DevTools")
|
||||
|
||||
$also_remove_webview = 0
|
||||
if ($also_remove_webview -eq 1) {
|
||||
$remove_win32 += "Microsoft EdgeWebView"
|
||||
$remove_appx += "WebExperience", "Win32WebViewHost"
|
||||
}
|
||||
|
||||
# Administrative Privileges Check
|
||||
$privileges = @(
|
||||
'SeSecurityPrivilege',
|
||||
'SeTakeOwnershipPrivilege',
|
||||
'SeBackupPrivilege',
|
||||
'SeRestorePrivilege'
|
||||
)
|
||||
|
||||
foreach ($privilege in $privileges) {
|
||||
[System.Diagnostics.Process]::SetPrivilege($privilege, 2)
|
||||
}
|
||||
|
||||
# Edge Removal Procedures
|
||||
$processesToShutdown = @(
|
||||
'explorer', 'Widgets', 'widgetservice', 'msedgewebview2', 'MicrosoftEdge*', 'chredge',
|
||||
'msedge', 'edge', 'msteams', 'msfamily', 'WebViewHost', 'Clipchamp'
|
||||
)
|
||||
|
||||
Stop-Process -Name "explorer" -Force -ErrorAction SilentlyContinue
|
||||
$processesToShutdown | ForEach-Object {
|
||||
Stop-Process -Name $_ -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$MS = ($env:ProgramFiles, ${env:ProgramFiles(x86)})[[Environment]::Is64BitOperatingSystem] + '\Microsoft\Edge\Application\msedge.exe'
|
||||
|
||||
Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe" -Recurse -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge' -Recurse -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM' -Recurse -ErrorAction SilentlyContinue
|
||||
|
||||
New-Item -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Force -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Name '(Default)' -Value "`"$MS`" --single-argument %%1" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
New-Item -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Force -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Name '(Default)' -Value "`"$MS`" --single-argument %%1" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
$registryPaths = @('HKLM:\SOFTWARE\Policies', 'HKLM:\SOFTWARE', 'HKLM:\SOFTWARE\WOW6432Node')
|
||||
$edgeProperties = @('InstallDefault', 'Install{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}', 'Install{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}')
|
||||
foreach ($path in $registryPaths) {
|
||||
foreach ($prop in $edgeProperties) {
|
||||
Remove-ItemProperty -Path "$path\Microsoft\EdgeUpdate" -Name $prop -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
$edgeupdate = 'Microsoft\EdgeUpdate\Clients\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}'
|
||||
$webvupdate = 'Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}'
|
||||
$on_actions = @('on-os-upgrade', 'on-logon', 'on-logon-autolaunch', 'on-logon-startup-boost')
|
||||
$registryBases = @('HKLM:\SOFTWARE', 'HKLM:\SOFTWARE\Wow6432Node')
|
||||
foreach ($base in $registryBases) {
|
||||
foreach ($launch in $on_actions) {
|
||||
Remove-Item -Path "$base\$edgeupdate\Commands\$launch" -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path "$base\$webvupdate\Commands\$launch" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
$registryPaths = @('HKCU:', 'HKLM:')
|
||||
$nodes = @('', '\Wow6432Node')
|
||||
foreach ($regPath in $registryPaths) {
|
||||
foreach ($node in $nodes) {
|
||||
foreach ($i in $remove_win32) {
|
||||
Remove-ItemProperty -Path "$regPath\SOFTWARE${node}\Microsoft\Windows\CurrentVersion\Uninstall\$i" -Name 'NoRemove' -Force -ErrorAction SilentlyContinue
|
||||
New-Item -Path "$regPath\SOFTWARE${node}\Microsoft\EdgeUpdateDev" -Force | Out-Null
|
||||
Set-ItemProperty -Path "$regPath\SOFTWARE${node}\Microsoft\EdgeUpdateDev" -Name 'AllowUninstall' -Value 1 -Type Dword -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$foldersToSearch = @('LocalApplicationData', 'ProgramFilesX86', 'ProgramFiles') | ForEach-Object {
|
||||
[Environment]::GetFolderPath($_)
|
||||
}
|
||||
|
||||
$edges = @()
|
||||
$bhoFiles = @()
|
||||
|
||||
foreach ($folder in $foldersToSearch) {
|
||||
$bhoFiles += Get-ChildItem -Path "$folder\Microsoft\Edge*\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue
|
||||
|
||||
$edges += Get-ChildItem -Path "$folder\Microsoft\Edge*\setup.exe" -Recurse -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.FullName -notlike '*EdgeWebView*' }
|
||||
}
|
||||
|
||||
$destinationDir = "$env:SystemDrive\Scripts"
|
||||
New-Item -Path $destinationDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
foreach ($bhoFile in $bhoFiles) {
|
||||
if (Test-Path $bhoFile) {
|
||||
try {
|
||||
Copy-Item -Path $bhoFile -Destination "$destinationDir\ie_to_edge_stub.exe" -Force
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
|
||||
## Work on Appx Removals
|
||||
$provisioned = Get-AppxProvisionedPackage -Online
|
||||
$appxpackage = Get-AppxPackage -AllUsers
|
||||
$eol = @()
|
||||
|
||||
$store = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Store'
|
||||
$storeP = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Store\InstalledApplications'
|
||||
foreach ($app in $appxpackage) {
|
||||
$name = $app.Name
|
||||
if ($app.Name -eq "Microsoft.Edge") {
|
||||
$eol += $name
|
||||
} elseif ($app.Name -eq "Microsoft.EdgeBeta" -or $app.Name -eq "Microsoft.EdgeDev" -or $app.Name -eq "Microsoft.EdgeCanary" -or $app.Name -eq "Microsoft.MicrosoftEdge") {
|
||||
$eol += $name
|
||||
}
|
||||
}
|
||||
|
||||
$eolApps = $provisioned | Where-Object { $eol -contains $_.DisplayName }
|
||||
|
||||
foreach ($edge in $eolApps) {
|
||||
$edgeName = $edge.DisplayName
|
||||
if (-not ($skip -contains $edgeName)) {
|
||||
try {
|
||||
Remove-AppxProvisionedPackage -Online -PackageName $edgeName -ErrorAction SilentlyContinue
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($edge in $appxpackage) {
|
||||
$edgeName = $edge.Name
|
||||
if ($eol -contains $edgeName) {
|
||||
if (-not ($skip -contains $edgeName)) {
|
||||
try {
|
||||
Remove-AppxPackage -Package $edgeName -AllUsers -ErrorAction SilentlyContinue
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
## Redirect shortcuts
|
||||
$shortcut_path = "$env:Public\Desktop"
|
||||
$shortcut_file = 'Microsoft Edge.lnk'
|
||||
$full_path = Join-Path -Path $shortcut_path -ChildPath $shortcut_file
|
||||
|
||||
if (Test-Path $full_path) {
|
||||
Remove-Item -Path $full_path -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$shortcut_path = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs"
|
||||
$shortcut_file = 'Microsoft Edge.lnk'
|
||||
$full_path = Join-Path -Path $shortcut_path -ChildPath $shortcut_file
|
||||
|
||||
if (Test-Path $full_path) {
|
||||
Remove-Item -Path $full_path -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$edgePolicy = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge'
|
||||
if (-not (Test-Path $edgePolicy)) {
|
||||
New-Item -Path $edgePolicy -Force | Out-Null
|
||||
}
|
||||
|
||||
$edgePrefs = @{
|
||||
'Dword' = @{
|
||||
'BrowserReplacementEnabled' = 1
|
||||
'HideFirstRunExperience' = 1
|
||||
'HideImportEdgeFavoritesPrompt' = 1
|
||||
'HideSyncSetupExperience' = 1
|
||||
'FavoritesBarVisibility' = 1
|
||||
}
|
||||
'String' = @{
|
||||
'AutoplayAllowed' = 'AllowOnce'
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entryType in $edgePrefs.Keys) {
|
||||
foreach ($prefName in $edgePrefs[$entryType].Keys) {
|
||||
Set-ItemProperty -Path $edgePolicy -Name $prefName -Value $edgePrefs[$entryType][$prefName] -Type $entryType -Force
|
||||
}
|
||||
}
|
||||
|
||||
# Output Results
|
||||
Write-Host "Edge Removal Complete" -ForegroundColor Green
|
||||
# Powershell Conversion and Refactor by Chris Titus Tech
|
||||
# Updated By Taylor Christian Nesome 8/6/2024
|
||||
|
||||
# Define constants and initial configuration
|
||||
$ScriptVersion = "2023.05.10"
|
||||
<#
|
||||
.SYNOPSIS
|
||||
This script removes Microsoft Edge and related components from the system.
|
||||
|
||||
.DESCRIPTION
|
||||
This script performs the following tasks:
|
||||
- Terminates Edge-related processes.
|
||||
- Removes registry entries associated with Microsoft Edge.
|
||||
- Uninstalls Edge-related AppX packages.
|
||||
- Cleans up shortcut files.
|
||||
- Configures Edge policy settings to prevent reinstallation.
|
||||
|
||||
.NOTES
|
||||
Updated by Taylor Christian Newsome
|
||||
Version: 2024.08.06
|
||||
#>
|
||||
|
||||
# Define constants and initial configuration
|
||||
$ScriptVersion = "2024.08.06"
|
||||
$EdgeProcessesToShutdown = @('explorer', 'Widgets', 'widgetservice', 'msedgewebview2', 'MicrosoftEdge*', 'chredge', 'msedge', 'edge', 'msteams', 'msfamily', 'WebViewHost', 'Clipchamp')
|
||||
$EdgeRemovalOptions = @{
|
||||
RemoveWin32 = @("Microsoft Edge", "Microsoft Edge Update")
|
||||
@ -198,56 +31,133 @@ $EdgeRemovalOptions = @{
|
||||
AlsoRemoveWebView = $false
|
||||
}
|
||||
|
||||
# Define main function to remove Microsoft Edge components
|
||||
function Remove-MicrosoftEdge {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
# Function to shutdown processes related to Microsoft Edge
|
||||
function Stop-EdgeProcesses {
|
||||
$EdgeProcessesToShutdown | ForEach-Object {
|
||||
Stop-Process -Name $_ -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
# Function to remove registry entries related to Microsoft Edge
|
||||
function Remove-EdgeRegistryEntries {
|
||||
# Clean up certain registry entries
|
||||
Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe" -Recurse -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe" -Recurse -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge' -Recurse -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path 'Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM' -Recurse -ErrorAction SilentlyContinue
|
||||
|
||||
# Create new registry entries
|
||||
$EdgeExecutablePath = ($env:ProgramFiles, ${env:ProgramFiles(x86)})[[Environment]::Is64BitOperatingSystem] + '\Microsoft\Edge\Application\msedge.exe'
|
||||
New-Item -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Force -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\microsoft-edge\shell\open\command" -Name '(Default)' -Value "`"$EdgeExecutablePath`" --single-argument %%1" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
New-Item -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Force -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path "HKLM:\SOFTWARE\Classes\MSEdgeHTM\shell\open\command" -Name '(Default)' -Value "`"$EdgeExecutablePath`" --single-argument %%1" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# Function to remove Microsoft Edge AppX packages
|
||||
function Remove-EdgeAppxPackages {
|
||||
$EdgeRemovalOptions.RemoveAppx | ForEach-Object {
|
||||
# Remove provisioned packages
|
||||
Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like "*$_*" -and $EdgeRemovalOptions.Skip -notcontains $_.PackageName } | Remove-AppxProvisionedPackage -Online -AllUsers -ErrorAction SilentlyContinue
|
||||
|
||||
# Remove installed packages
|
||||
Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like "*$_*" -and $EdgeRemovalOptions.Skip -notcontains $_.PackageFullName } | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
# Function to remove Microsoft Edge processes, registry entries, and AppX packages
|
||||
try {
|
||||
Stop-EdgeProcesses
|
||||
Remove-EdgeRegistryEntries
|
||||
Remove-EdgeAppxPackages
|
||||
Write-Output "Microsoft Edge components have been successfully removed."
|
||||
} catch {
|
||||
Write-Error "Failed to remove Microsoft Edge components: $_"
|
||||
# Function to check if the script is running with administrative privileges
|
||||
function Test-Admin {
|
||||
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||
Write-Error "The script must be run as an Administrator."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Execute the main function
|
||||
Remove-MicrosoftEdge
|
||||
# Function to stop Edge-related processes
|
||||
function Stop-EdgeProcesses {
|
||||
param([string[]]$ProcessesToStop)
|
||||
foreach ($process in $ProcessesToStop) {
|
||||
try {
|
||||
Stop-Process -Name $process -Force -ErrorAction Stop
|
||||
Write-Output "Successfully stopped process: $process"
|
||||
} catch {
|
||||
Write-Error "Failed to stop process: $process. $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Function to remove registry entries related to Microsoft Edge
|
||||
function Remove-EdgeRegistryEntries {
|
||||
param([string[]]$RegistryPaths)
|
||||
foreach ($path in $RegistryPaths) {
|
||||
try {
|
||||
Remove-Item -Path $path -Recurse -Force -ErrorAction Stop
|
||||
Write-Output "Successfully removed registry path: $path"
|
||||
} catch {
|
||||
Write-Error "Failed to remove registry path: $path. $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Function to remove Microsoft Edge AppX packages
|
||||
function Remove-EdgeAppxPackages {
|
||||
param([string[]]$AppxPackagesToRemove)
|
||||
$provisionedPackages = Get-AppxProvisionedPackage -Online
|
||||
foreach ($package in $AppxPackagesToRemove) {
|
||||
try {
|
||||
$packagesToRemove = $provisionedPackages | Where-Object { $_.DisplayName -like "*$package*" }
|
||||
foreach ($pkg in $packagesToRemove) {
|
||||
Remove-AppxProvisionedPackage -Online -PackageName $pkg.PackageName -ErrorAction Stop
|
||||
Write-Output "Successfully removed provisioned package: $pkg.DisplayName"
|
||||
}
|
||||
|
||||
$installedPackages = Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like "*$package*" }
|
||||
foreach ($pkg in $installedPackages) {
|
||||
Remove-AppxPackage -Package $pkg.PackageFullName -AllUsers -ErrorAction Stop
|
||||
Write-Output "Successfully removed installed package: $pkg.PackageFullName"
|
||||
}
|
||||
} catch {
|
||||
Write-Error "Failed to remove AppX package: $package. $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Function to remove shortcuts related to Microsoft Edge
|
||||
function Remove-EdgeShortcuts {
|
||||
param([string[]]$ShortcutPaths)
|
||||
foreach ($path in $ShortcutPaths) {
|
||||
if (Test-Path $path) {
|
||||
try {
|
||||
Remove-Item -Path $path -Force -ErrorAction Stop
|
||||
Write-Output "Successfully removed shortcut: $path"
|
||||
} catch {
|
||||
Write-Error "Failed to remove shortcut: $path. $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Function to configure Edge policy settings
|
||||
function Configure-EdgePolicy {
|
||||
param([hashtable]$PolicySettings)
|
||||
$edgePolicyPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge'
|
||||
if (-not (Test-Path $edgePolicyPath)) {
|
||||
try {
|
||||
New-Item -Path $edgePolicyPath -Force | Out-Null
|
||||
Write-Output "Created Edge policy registry path: $edgePolicyPath"
|
||||
} catch {
|
||||
Write-Error "Failed to create Edge policy registry path: $edgePolicyPath. $_"
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entryType in $PolicySettings.Keys) {
|
||||
foreach ($prefName in $PolicySettings[$entryType].Keys) {
|
||||
try {
|
||||
Set-ItemProperty -Path $edgePolicyPath -Name $prefName -Value $PolicySettings[$entryType][$prefName] -Type $entryType -Force
|
||||
Write-Output "Successfully set Edge policy: $prefName = $($PolicySettings[$entryType][$prefName])"
|
||||
} catch {
|
||||
Write-Error "Failed to set Edge policy: $prefName. $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Main execution
|
||||
try {
|
||||
Test-Admin
|
||||
Stop-EdgeProcesses -ProcessesToStop $EdgeProcessesToShutdown
|
||||
Remove-EdgeRegistryEntries -RegistryPaths @(
|
||||
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe",
|
||||
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ie_to_edge_stub.exe",
|
||||
"Registry::HKEY_Users\S-1-5-21*\Software\Classes\microsoft-edge",
|
||||
"Registry::HKEY_Users\S-1-5-21*\Software\Classes\MSEdgeHTM"
|
||||
)
|
||||
Remove-EdgeAppxPackages -AppxPackagesToRemove $EdgeRemovalOptions.RemoveAppx
|
||||
Remove-EdgeShortcuts -ShortcutPaths @(
|
||||
"$env:Public\Desktop\Microsoft Edge.lnk",
|
||||
"$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk"
|
||||
)
|
||||
Configure-EdgePolicy -PolicySettings @{
|
||||
'Dword' = @{
|
||||
'BrowserReplacementEnabled' = 1
|
||||
'HideFirstRunExperience' = 1
|
||||
'HideImportEdgeFavoritesPrompt' = 1
|
||||
'HideSyncSetupExperience' = 1
|
||||
'FavoritesBarVisibility' = 1
|
||||
}
|
||||
'String' = @{
|
||||
'AutoplayAllowed' = 'AllowOnce'
|
||||
}
|
||||
}
|
||||
Write-Output "Microsoft Edge components have been successfully removed."
|
||||
} catch {
|
||||
Write-Error "An error occurred during execution: $_"
|
||||
}
|
||||
|
||||
Remove-MicrosoftEdge
|
||||
|
Loading…
Reference in New Issue
Block a user