Skip to content

Commit

Permalink
Add script to forcefully remove ebpf-for-windows (#3441)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
Co-authored-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan-Jowett and Alan Jowett authored Apr 12, 2024
1 parent 73647f8 commit e3dc614
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions scripts/Cleanup-Installer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: MIT

# This script exists to forcefully remove all eBPF components when an uninstall is not possible.
# This script is not intended to be run on a production system. It is intended to be run on a test system where the eBPF components are being tested.

# Find the registry key for the eBPF for Windows product and remove it.
$keyName = (Get-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\*\InstallProperties" | Where-Object { $_.GetValue("DisplayName") -eq "eBPF for Windows"}).Name
if ($keyName.Length -gt 0) {
$keyName = $keyName.Substring(0, $keyName.LastIndexOf("\"))
$registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\" + $keyName.Substring($keyName.LastIndexOf("\") + 1)
Remove-Item -Path $registryPath -Recurse
}

# Find the registry key for the eBPF for Windows product and remove it.
$keyName = (Get-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object { $_.GetValue("DisplayName") -eq "eBPF for Windows"}).Name
if ($keyName.Length -gt 0) {
$keyName = $keyName.SubString($keyName.LastIndexOf("\") + 1)
$registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $keyName
Remove-Item -Path $registryPath -Recurse
}

# Stop and remove the eBPF services.
net.exe stop ebpfsvc
sc.exe delete ebpfsvc

# Stop and remove the eBPF core driver.
net.exe stop ebpfcore
sc.exe delete ebpfcore

# Stop and remove the eBPF extension driver.
net.exe stop netebpfext
sc.exe delete netebpfext

# Remove the eBPF for Windows installation directory.
$installPath = "C:\Program Files\ebpf-for-windows"
if (Test-Path $installPath) {
Remove-Item -Path "C:\Program Files\ebpf-for-windows" -Recurse -Force
}

# Set the exit code to 0 to indicate success.
$global:LASTEXITCODE = 0

0 comments on commit e3dc614

Please sign in to comment.