-
Notifications
You must be signed in to change notification settings - Fork 0
/
win_uninstall.ps1
84 lines (74 loc) · 2.96 KB
/
win_uninstall.ps1
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
# ****************************************************************************
# **
# ** Copyright (C) 2023 EUNOMATIX
# ** This program is free software: you can redistribute it and/or modify
# ** it under the terms of the GNU General Public License as published by
# ** the Free Software Foundation, either version 3 of the License, or
# ** any later version.
# **
# ** This program is distributed in the hope that it will be useful,
# ** but WITHOUT ANY WARRANTY; without even the implied warranty of
# ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# ** GNU General Public License for more details.
# **
# ** You should have received a copy of the GNU General Public License
# ** along with this program. If not, see <https://www.gnu.org/licenses/>.
# **
# ** Contact: info@eunomatix.com
# **
# **************************************************************************/
# PowerShell script for uninstalling browsermon on Windows
# Check if running with administrative privileges
$isAdmin = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).Groups -match "S-1-5-32-544"
if (-not $isAdmin) {
Write-Host "Please run this script with administrative privileges."
Read-Host "Press Enter to close this window..."
Exit
}
# Define the target directory
$TARGET_DIR = "C:\browsermon"
# Stop the browsermon service if it's running
if (Get-Service -Name "browsermon" -ErrorAction SilentlyContinue) {
Stop-Service "browsermon"
}
# Wait for the service to stop
do {
$serviceStatus = Get-Service -Name "browsermon" -ErrorAction SilentlyContinue
if ($serviceStatus -eq $null -or $serviceStatus.Status -eq "Stopped") {
break
}
Start-Sleep -Seconds 2
} while ($true)
# Remove the browsermon service using the browsermon.exe remove command
$browsermonExePath = Join-Path $TARGET_DIR "browsermon.exe"
Start-Process -FilePath $browsermonExePath -ArgumentList "remove"
# Wait for the service to be removed
do {
$serviceStatus = Get-Service -Name "browsermon" -ErrorAction SilentlyContinue
if ($serviceStatus -eq $null) {
break
}
Start-Sleep -Seconds 2
} while ($true)
# Wait until the browsermon.exe process is not running before deleting the file
do {
$browsermonProcess = Get-Process -Name "browsermon" -ErrorAction SilentlyContinue
if ($browsermonProcess -eq $null) {
break
}
Start-Sleep -Seconds 2
} while ($true)
# Forcefully delete the browsermon.exe file
try {
Remove-Item -Path $browsermonExePath -Force -ErrorAction Stop
} catch {
Write-Host "Error: Unable to delete $browsermonExePath. Please delete this file manually."
}
# Delete the installation directory
try {
Remove-Item -Path $TARGET_DIR -Recurse -Force -ErrorAction Stop
} catch {
Write-Host "Error: Unable to delete $TARGET_DIR. Please delete this directory manually."
}
Write-Host "Uninstallation complete."
Read-Host "Press Enter to close this window..."