Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ecourtneyjc
Copy link

Issues

  • -

What does this solve?

Gives support and customers a script to automatically remove broken Windows agent installs.

Is there anything particularly tricky?

Since the GUID used in the registry to identify the current installation is random, discovery of the JC Agent GUID is done via recursive search through 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products' to obtain the ID used to remove the remaining keys.

How should this be tested?

Install the JumpCloud Windows Agent
Confirm the existence of the following registry entries

  • HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products<JumpCloud Agent GUID>
  • HKCR:\Installer\Products<JumpCloud Agent GUID>
  • HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall<JC MSI Installation ID>
  • HKLM:\Software\JumpCloud
  • HKLM:\SOFTWARE\Classes\Installer\Products<JumpCloud Agent GUID>

Run the UninstallWindowsAgent.ps1 script as an administrator.
Verify the above keys are removed
Verify the JumpCloud Agent service is no longer present.
Verify that the JumpCloud Agent folder is empty aside from:

  • cpoidc
  • JumpCloudCredentialProvider-X.XXX.X.dll

Reinstall Windows Agent using preferred method.
Confirm agent reinstall is successful.

Screenshots

@ecourtneyjc ecourtneyjc marked this pull request as ready for review October 3, 2024 19:00
@ecourtneyjc ecourtneyjc requested a review from a team as a code owner October 3, 2024 19:00
Copy link
Contributor

@jworkmanjc jworkmanjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I tested this just now. Two thoughts:

The script does tell me that the uninstall Key does not exist. And I believe it's due to the fact that the uninstall key looks something like this:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{E14D51FF-380F-4964-9581-665DED7F58C1}

Where curly braces encase the GUID key.

Screenshot 2024-10-07 at 9 32 42 AM

Though everything seems to be removed I think the messaging is confusing here.

FWIW my registry keys were as follows:
`Computer\HKEY_CLASSES_ROOT\Installer\Products\FF15D41EF0834694591866D5DEF7851C

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\FF15D41EF0834694591866D5DEF7851C
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{E14D51FF-380F-4964-9581-665DED7F58C1}
Computer\HKEY_LOCAL_MACHINE\Software\JumpCloud
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\FF15D41EF0834694591866D5DEF7851C`

I'm curious if you are seeing the same verbose messaging @ecourtneyjc?

@kmaranionjc kmaranionjc self-requested a review October 7, 2024 19:03
Copy link
Contributor

@kmaranionjc kmaranionjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ed, thanks for the work here. I added some review points. Couple things that pop up from my tests is:

  1. Find-JumpCloudGUID gets both JCAGent GUID and MSI installation ID. It should be separated since it get's called and looped through Remove-JumpCloud function which results on some errors.

New-PSDrive -Name "HKCR" -PSProvider Registry -Root "HKEY_CLASSES_ROOT" -ErrorAction SilentlyContinue

# Function to recursively search for DisplayName in the registry
function Find-JumpCloudGUID {
Copy link
Contributor

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?
image

Copy link
Contributor

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.

}
}

# Stopping and removing the service
Copy link
Contributor

Choose a reason for hiding this comment

The 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

function Remove-JumpCloud {
$guids = Find-JumpCloudGUID

foreach ($guid in $guids) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got GUID and MSI Install ID when I ran Find-JumpCloudGUID. Both should not be looped together.


# Stopping and removing the service
$serviceName = "jumpcloud-agent"
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was ran twice since I have two $guids values
image

if (Test-Path $key) {
Remove-Item -Path $key -Recurse -Force -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "Registry key $key not found."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance of MSI installation ID on the $guids variable.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants