hashicorp/nomad · error
could not get existing service - %w
Error message
could not get existing service - %w
What it means
performUninstall wraps the error from m.GetService(WINDOWS_SERVICE_NAME) after confirming the service is registered. It means the handle to the existing service could not be opened, typically due to insufficient SCM access rights, so the uninstall cannot proceed to stop/delete the service.
Source
Thrown at command/windows_service_uninstall.go:102
c.Ui.Info("Successfully uninstalled nomad Windows service")
return 0
}
func (c *WindowsServiceUninstallCommand) performUninstall(m winsvc.WindowsServiceManager) error {
// Check that the nomad service is currently registered
exists, err := m.IsServiceRegistered(winsvc.WINDOWS_SERVICE_NAME)
if err != nil {
return fmt.Errorf("unable to check for existing service - %w", err)
}
if !exists {
return nil
}
// Grab the service and ensure the service is stopped
srvc, err := m.GetService(winsvc.WINDOWS_SERVICE_NAME)
if err != nil {
return fmt.Errorf("could not get existing service - %w", err)
}
defer srvc.Close()
if err := srvc.Stop(); err != nil {
return fmt.Errorf("unable to stop service - %w", err)
}
// Remove the service from the event log
if err := srvc.DisableEventlog(); err != nil {
return fmt.Errorf("could not remove eventlog configuration - %w", err)
}
// Finally, delete the service
if err := srvc.Delete(); err != nil {
return fmt.Errorf("could not delete service - %w", err)
}
return nilView on GitHub (pinned to 482b49bf1a)
Solutions
- Re-run the uninstall from an elevated Administrator prompt
- Check the wrapped error code (ERROR_ACCESS_DENIED implies elevation needed)
- Verify the service still exists with `sc query nomad` and retry
- Reboot or restart SCM if the service record is in an inconsistent state
Defensive patterns
Strategy: try-catch
Try / catch
if err := uninstallCmd.Run(); err != nil {
if strings.Contains(err.Error(), "could not get existing service") {
// check `sc query nomad`; re-run elevated
}
} Prevention
- Run uninstalls elevated
- Avoid concurrent scripts deleting the same service
- Confirm the service exists with `sc query nomad` before uninstalling
When it happens
Trigger: GetService fails because the process lacks SERVICE_QUERY_STATUS/QUERY_CONFIG rights (non-elevated run), the service record disappeared between the existence check and the lookup, or SCM access is denied by policy.
Common situations: Uninstalling from a non-admin shell; the service was deleted concurrently by another process; security software restricting SCM handles.
Related errors
- unable to check for existing service - %w
- service registration check failed - %w
- unable to create service - %w
- cannot create copy - %s
- unable to stop service - %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/a1945e0fefb1800a.
Report an issue: GitHub.