{"record":{"id":"9ce3babc3b7e0d4c","repo":"hashicorp/nomad","slug":"unable-to-check-for-existing-service-w-9ce3ba","errorCode":null,"errorMessage":"unable to check for existing service - %w","messagePattern":"unable to check for existing service - %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_uninstall.go","lineNumber":92,"sourceCode":"\t\tc.Ui.Error(fmt.Sprintf(\"Could not connect to Windows service manager - %s\", err))\n\t\treturn 1\n\t}\n\tdefer m.Close()\n\n\tif err := c.performUninstall(m); err != nil {\n\t\tc.Ui.Error(fmt.Sprintf(\"Service uninstall failed: %s\", err))\n\t\treturn 1\n\t}\n\n\tc.Ui.Info(\"Successfully uninstalled nomad Windows service\")\n\treturn 0\n}\n\nfunc (c *WindowsServiceUninstallCommand) performUninstall(m winsvc.WindowsServiceManager) error {\n\t// Check that the nomad service is currently registered\n\texists, err := m.IsServiceRegistered(winsvc.WINDOWS_SERVICE_NAME)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to check for existing service - %w\", err)\n\t}\n\n\tif !exists {\n\t\treturn nil\n\t}\n\n\t// Grab the service and ensure the service is stopped\n\tsrvc, err := m.GetService(winsvc.WINDOWS_SERVICE_NAME)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not get existing service - %w\", err)\n\t}\n\tdefer srvc.Close()\n\n\tif err := srvc.Stop(); err != nil {\n\t\treturn fmt.Errorf(\"unable to stop service - %w\", err)\n\t}\n\n\t// Remove the service from the event log","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_uninstall.go#L74-L110","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running `nomad windows service uninstall` from a non-elevated shell; SCM access denied by policy; corrupted service manager state.","solutions":["Run the uninstall command from an elevated (Administrator) prompt","Inspect the wrapped error for a specific Windows error code (e.g. access denied)","Check that the Service Control Manager is healthy (sc query works)","Retry after fixing SCM permissions or machine policy"],"exampleFix":"# before\nC:\\> nomad windows service uninstall\nunable to check for existing service - access denied\n# after (elevated)\nC:\\> nomad windows service uninstall","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"sc\", \"query\", \"nomad\").CombinedOutput()\nif err != nil {\n    // if access denied, re-run elevated before uninstalling\n    _ = out\n}","preventionTips":["Always run service install/uninstall from an elevated prompt","Verify SCM access with `sc query` first","Avoid running under restricted service accounts or policy-limited shells"],"tags":["go","windows","service-control-manager","permissions"],"backgroundTag":"windows-service-access-denied","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}