{"record":{"id":"8b9a09569d76662e","repo":"hashicorp/nomad","slug":"cannot-detect-windows-programdata-path","errorCode":null,"errorMessage":"cannot detect Windows ProgramData path","messagePattern":"cannot detect Windows ProgramData path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/winsvc/path_windows.go","lineNumber":183,"sourceCode":"\t\tw.SystemDrive = os.Getenv(\"SystemDrive\")\n\t\tif w.SystemDrive == \"\" {\n\t\t\tw.loadErr = fmt.Errorf(\"cannot detect Windows SystemDrive path\")\n\t\t\treturn\n\t\t}\n\t\tw.SystemRoot = strings.ReplaceAll(os.Getenv(\"SystemDrive\"), \"SystemDrive\", w.SystemDrive)\n\n\t\tw.ProgramData = os.Getenv(\"ProgramData\")\n\t\tif w.ProgramData == \"\" {\n\t\t\tpdKey, err := registry.OpenKey(registry.LOCAL_MACHINE,\n\t\t\t\t`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList`, registry.QUERY_VALUE)\n\t\t\tif err == nil {\n\t\t\t\tif pdVal, _, err := pdKey.GetStringValue(\"ProgramData\"); err == nil {\n\t\t\t\t\tw.ProgramData = pdVal\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif w.ProgramData == \"\" {\n\t\t\tw.loadErr = fmt.Errorf(\"cannot detect Windows ProgramData path\")\n\t\t\treturn\n\t\t}\n\t\tw.ProgramData = strings.ReplaceAll(w.ProgramData, \"SystemDrive\", w.SystemDrive)\n\n\t\tw.ProgramFiles = os.Getenv(\"ProgramFiles\")\n\t\tif w.ProgramFiles == \"\" {\n\t\t\tpdKey, err := registry.OpenKey(registry.LOCAL_MACHINE,\n\t\t\t\t`SOFTWARE\\Microsoft\\Windows\\CurrentVersion`, registry.QUERY_VALUE)\n\t\t\tif err == nil {\n\t\t\t\tif pdVal, _, err := pdKey.GetStringValue(\"ProgramFilesDir\"); err == nil {\n\t\t\t\t\tw.ProgramFiles = pdVal\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif w.ProgramFiles == \"\" {\n\t\t\tw.loadErr = fmt.Errorf(\"cannot detect Windows ProgramFiles path\")\n\t\t\treturn\n\t\t}","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/winsvc/path_windows.go#L165-L201","documentation":"The winsvc helper cannot determine the Windows ProgramData directory for a Windows service environment. It first checks the ProgramData environment variable, and falls back to reading the registry value HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\ProgramData. If both are empty, it records this error in w.loadErr, and the first call that touches the path map returns it.","triggerScenarios":"Calling any path lookup (e.g. for service config/data paths) on Windows when the ProgramData environment variable is unset AND the registry lookup via getStringsValue on 'Shell Folders'/'ProgramData' fails or returns an empty string.","commonSituations":"Running inside a stripped-down service context or container where environment variables are scrubbed; running on non-Windows platforms compiled with windows tags; corrupted registry Shell Folders key; custom minimal Windows images.","solutions":["Set the ProgramData environment variable (e.g. set ProgramData=C:\\ProgramData) for the process/service account before starting the app.","Verify the registry key HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders contains a ProgramData value and repair it if missing.","Run the process as a normal Windows service account under a standard Windows installation so the default environment/registry are present.","If running in a container/emulator, mount or provide a valid ProgramData path in the environment."],"exampleFix":"// before (no env, registry lookup fails)\nw.ProgramData == \"\" -> cannot detect Windows ProgramData path\n\n// after (deployment/launch fix)\n# in service wrapper or container definition\nset ProgramData=C:\\ProgramData","handlingStrategy":"validation","validationCode":"if runtime.GOOS == \"windows\" && os.Getenv(\"ProgramData\") == \"\" {\n    // probe or set before calling path helpers\n    return errors.New(\"ProgramData env var missing; set it before use\")\n}","typeGuard":null,"tryCatchPattern":"if err := winsvc.PathErr(); err != nil {\n    if strings.Contains(err.Error(), \"cannot detect Windows ProgramData path\") {\n        // fall back to a computed default or abort early\n    }\n}","preventionTips":["Ensure the service account's environment includes standard Windows variables.","Smoke-test path resolution on minimal Windows images before deploy.","Log env at startup in debug mode to catch scrubbed environments."],"tags":["windows","environment","registry","paths"],"backgroundTag":"missing-env-var","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"}