{"record":{"id":"2e12df44accb8120","repo":"hashicorp/nomad","slug":"unable-to-create-service-w","errorCode":null,"errorMessage":"unable to create service - %w","messagePattern":"unable to create service - %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":224,"sourceCode":"\t\tif err := srvc.Configure(winsvc.WindowsServiceConfiguration{\n\t\t\tStartType:      winsvc.StartAutomatic,\n\t\t\tDisplayName:    winsvc.WINDOWS_SERVICE_DISPLAY_NAME,\n\t\t\tDescription:    winsvc.WINDOWS_SERVICE_DESCRIPTION,\n\t\t\tBinaryPathName: cmd,\n\t\t}); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to configure service - %w\", err)\n\t\t}\n\t} else {\n\t\tsrvc, err = m.CreateService(winsvc.WINDOWS_SERVICE_NAME, opts.binaryPath,\n\t\t\twinsvc.WindowsServiceConfiguration{\n\t\t\t\tStartType:      winsvc.StartAutomatic,\n\t\t\t\tDisplayName:    winsvc.WINDOWS_SERVICE_DISPLAY_NAME,\n\t\t\t\tDescription:    winsvc.WINDOWS_SERVICE_DESCRIPTION,\n\t\t\t\tBinaryPathName: cmd,\n\t\t\t},\n\t\t)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to create service - %w\", err)\n\t\t}\n\t\tdefer srvc.Close()\n\t}\n\n\t// Enable the service in the Windows eventlog\n\tif err := srvc.EnableEventlog(); err != nil {\n\t\treturn fmt.Errorf(\"could not configure eventlog - %w\", err)\n\t}\n\n\t// Ensure the service is stopped\n\tif err := srvc.Stop(); err != nil {\n\t\treturn fmt.Errorf(\"could not stop service - %w\", err)\n\t}\n\n\t// Start the service so the new binary is in use\n\tif err := srvc.Start(); err != nil {\n\t\treturn fmt.Errorf(\"could not start service - %w\", err)\n\t}","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L206-L242","documentation":"Returned by serviceInstall when WindowsServiceManager.CreateService fails to register a new Nomad Windows service (the registry showed no existing one). The service could not be created with the supplied binary path and configuration.","triggerScenarios":"Creating the Windows service 'Nomad' fails: ERROR_ACCESS_DENIED without elevation, service name already exists but the earlier check missed it, or disk full / invalid parameters.","commonSituations":"Non-elevated install attempt; leftover service entry deleted-but-pending (marked for deletion); security software blocking service creation.","solutions":["Run the install from an elevated (Administrator) shell","If a stale entry exists, `sc.exe delete nomad`, reboot, and retry","Check the chained %w cause for the exact SCM error code","Ensure sufficient free disk space and a valid binary path"],"exampleFix":"// before\nPS> nomad windows install\nunable to create service - Access is denied\n// after\nPS (admin)> nomad windows install","handlingStrategy":"try-catch","validationCode":"if !isAdmin() {\n\tlog.Fatal(\"creating the Nomad service requires an elevated shell\")\n}\nout, _ := exec.Command(\"sc.exe\", \"query\", \"nomad\").CombinedOutput()\nlog.Printf(\"service pre-check: %s\", out)","typeGuard":null,"tryCatchPattern":"srvc, err = m.CreateService(winsvc.WINDOWS_SERVICE_NAME, opts.binaryPath, cfg)\nif err != nil {\n\tif errors.Is(err, windows.ERROR_SERVICE_EXISTS) {\n\t\t// fall back to the GetService/Configure update path\n\t}\n\treturn fmt.Errorf(\"unable to create service - %w\", err)\n}","preventionTips":["Run installs elevated","Handle ERROR_SERVICE_EXISTS by updating instead of creating","Clear marked-for-deletion entries via reboot","Verify disk space and valid paths before install"],"tags":["windows","service-control-manager","permissions"],"backgroundTag":"service-creation-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"}