-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial commit of the Windows uninstall script #610
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Function to check if Powershell is 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) | ||
} | ||
|
||
if (-not (Test-Administrator)) { | ||
Write-Warning "This script needs to be run as an administrator." | ||
exit | ||
} | ||
|
||
# Create HKCR Mapping | ||
New-PSDrive -Name "HKCR" -PSProvider Registry -Root "HKEY_CLASSES_ROOT" -ErrorAction SilentlyContinue | ||
|
||
# Function to recursively search for DisplayName in the registry | ||
function Find-JumpCloudGUID { | ||
$rootKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products" | ||
$uninstallKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | ||
$jumpcloudGUIDs = @() | ||
|
||
# Searching Installed Products | ||
Get-ChildItem -Path $rootKey | ForEach-Object { | ||
$installPropertiesPath = "$($_.PSPath)\InstallProperties" | ||
try { | ||
$displayName = (Get-ItemProperty -Path $installPropertiesPath -ErrorAction SilentlyContinue).DisplayName | ||
if ($displayName -like "*JumpCloud Agent*") { | ||
$guid = $_.PSChildName | ||
$jumpcloudGUIDs += $guid | ||
} | ||
} catch { | ||
Write-Host "Error accessing $installPropertiesPath" | ||
} | ||
} | ||
|
||
# Searching for the Uninstall Key | ||
Get-ChildItem -Path $uninstallKey | ForEach-Object { | ||
try { | ||
$displayName = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).DisplayName | ||
if ($displayName -like "*JumpCloud Agent*") { | ||
$uninstallGUID = $_.PSChildName | ||
$jumpcloudGUIDs += $uninstallGUID | ||
} | ||
} catch { | ||
Write-Host "Error accessing $($_.PSPath)" | ||
} | ||
} | ||
|
||
return $jumpcloudGUIDs | ||
} | ||
|
||
# Function to remove registry keys, JC folder, and JC service | ||
function Remove-JumpCloud { | ||
$guids = Find-JumpCloudGUID | ||
|
||
foreach ($guid in $guids) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got GUID and MSI Install ID when I ran |
||
# Removing registry keys | ||
$installerKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\$guid" | ||
$classesKey = "HKCR:\Installer\Products\$guid" | ||
$uninstallKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$guid" | ||
$jumpcloudSoftwareKey = "HKLM:\Software\JumpCloud" | ||
$jumpcloudClasses = "HKLM:\SOFTWARE\Classes\Installer\Products\$guid" | ||
|
||
$keysToDelete = @($installerKey, $classesKey, $uninstallKey, $jumpcloudSoftwareKey) | ||
|
||
foreach ($key in $keysToDelete) { | ||
if (Test-Path $key) { | ||
Remove-Item -Path $key -Recurse -Force -Verbose -ErrorAction SilentlyContinue | ||
} else { | ||
Write-Host "Registry key $key not found." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
|
||
# Stopping and removing the service | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should Stop-Service be before removing reg keys? A running agent might mess with key removals |
||
$serviceName = "jumpcloud-agent" | ||
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Stop-Service -Name $serviceName -Force -Verbose | ||
start-sleep 6 | ||
sc.exe delete $serviceName | ||
start-sleep 6 | ||
} else { | ||
Write-Host "Service $serviceName not found." | ||
} | ||
|
||
# Removing folder | ||
$jumpcloudFolder = "C:\Program Files\JumpCloud" | ||
if (Test-Path $jumpcloudFolder) { | ||
Remove-Item -Path $jumpcloudFolder -Recurse -ErrorAction SilentlyContinue | ||
} | ||
|
||
} | ||
} | ||
|
||
# Run the removal function | ||
Remove-JumpCloud |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When pulling the GUID, is it possible to have Multiple JCAgent GUIDs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the value with brackets MSI installation ID? It looks like it from
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall<JC MSI Installation ID>
. If so, pulling the MSI installation ID should be in a separate function from Find-JumpCloudGUID.