hashicorp/nomad · error

unable to check for existing service - %w

Error message

unable to check for existing service - %w

What it means

performUninstall wraps the error from the service manager's IsServiceRegistered(WINDOWS_SERVICE_NAME), the first step of uninstalling the Nomad Windows service. It means the uninstaller could not determine whether the service exists, so it aborts rather than blindly proceeding. This is not a 'service not found' case — that returns nil.

Source

Thrown at command/windows_service_uninstall.go:92

		c.Ui.Error(fmt.Sprintf("Could not connect to Windows service manager - %s", err))
		return 1
	}
	defer m.Close()

	if err := c.performUninstall(m); err != nil {
		c.Ui.Error(fmt.Sprintf("Service uninstall failed: %s", err))
		return 1
	}

	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

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Run the uninstall command from an elevated (Administrator) prompt
  2. Inspect the wrapped error for a specific Windows error code (e.g. access denied)
  3. Check that the Service Control Manager is healthy (sc query works)
  4. Retry after fixing SCM permissions or machine policy

Example fix

# before
C:\> nomad windows service uninstall
unable to check for existing service - access denied
# after (elevated)
C:\> nomad windows service uninstall
Defensive patterns

Strategy: try-catch

Try / catch

out, err := exec.Command("sc", "query", "nomad").CombinedOutput()
if err != nil {
    // if access denied, re-run elevated before uninstalling
    _ = out
}

Prevention

When it happens

Trigger: The Windows SCM (Service Control Manager) call underlying IsServiceRegistered fails — e.g. the uninstaller is not elevated, SCM is unreachable, or the manager handle is invalid while performUninstall runs.

Common situations: Running `nomad windows service uninstall` from a non-elevated shell; SCM access denied by policy; corrupted service manager state.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/9ce3babc3b7e0d4c. Report an issue: GitHub.