-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathuninstall-service.ps1
More file actions
118 lines (104 loc) · 3.83 KB
/
Copy pathuninstall-service.ps1
File metadata and controls
118 lines (104 loc) · 3.83 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
# AxonASP Service Uninstallation Script
#
# AxonASP Server
# Copyright (C) 2026 G3pix Ltda. All rights reserved.
#
# Developed by Lucas Guimarães - G3pix Ltda
# Contact: https://g3pix.com.br
# Project URL: https://g3pix.com.br/axonasp
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# Attribution Notice:
# If this software is used in other projects, the name "AxonASP Server"
# must be cited in the documentation or "About" section.
#
# Contribution Policy:
# Modifications to the core source code of AxonASP Server must be
# made available under this same license terms.
#
# --- Script Configuration ---
$ServiceExecutable = ".\axonasp-service.exe"
$ServiceName = "AxonASPServer"
# --- Function to check if running as Administrator ---
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# --- Function to display error message ---
function Write-ErrorMessage {
param([string]$Message)
Write-Host "ERROR: $Message" -ForegroundColor Red
}
# --- Function to display success message ---
function Write-SuccessMessage {
param([string]$Message)
Write-Host "SUCCESS: $Message" -ForegroundColor Green
}
# --- Function to display info message ---
function Write-InfoMessage {
param([string]$Message)
Write-Host "INFO: $Message" -ForegroundColor Cyan
}
# --- Main Script Execution ---
Write-InfoMessage "Starting AxonASP Service Uninstallation..."
# Check if running as Administrator
if (-not (Test-Administrator)) {
Write-ErrorMessage "This script must be run as Administrator."
Write-InfoMessage "Please run PowerShell as Administrator and try again."
exit 1
}
# Check if the service executable exists
if (-not (Test-Path $ServiceExecutable)) {
Write-ErrorMessage "Service executable not found at: $ServiceExecutable"
Write-InfoMessage "Please ensure axonasp-service.exe is in the current directory."
exit 1
}
# Check if service exists before attempting to stop/uninstall
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $service) {
Write-ErrorMessage "Service '$ServiceName' not found in the system."
Write-InfoMessage "There is nothing to uninstall."
exit 1
}
# Check current service status
Write-InfoMessage "Checking current service status..."
$currentStatus = $service.Status
Write-InfoMessage "Service Status: $currentStatus"
# Stop the service if it is running
if ($currentStatus -eq "Running") {
Write-InfoMessage "Stopping AxonASP Service..."
& $ServiceExecutable stop
if ($LASTEXITCODE -eq 0) {
Write-SuccessMessage "Service stopped successfully."
} else {
Write-ErrorMessage "Failed to stop service. Exit code: $LASTEXITCODE"
exit 1
}
} else {
Write-InfoMessage "Service is not running. Skipping stop command."
}
# Uninstall the service
Write-InfoMessage "Uninstalling AxonASP Service..."
& $ServiceExecutable uninstall
if ($LASTEXITCODE -eq 0) {
Write-SuccessMessage "Service uninstalled successfully."
} else {
Write-ErrorMessage "Failed to uninstall service. Exit code: $LASTEXITCODE"
exit 1
}
# Verify service is removed
Write-InfoMessage "Verifying service removal..."
Start-Sleep -Seconds 1
$serviceAfterRemoval = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($serviceAfterRemoval) {
Write-ErrorMessage "Service still exists after uninstall attempt."
exit 1
} else {
Write-SuccessMessage "Service has been successfully removed from the system."
}
Write-SuccessMessage "AxonASP Service uninstallation completed successfully!"
exit 0