{"record":{"id":"87c2f798501515d2","repo":"hashicorp/nomad","slug":"cannot-detect-windows-programfiles-path","errorCode":null,"errorMessage":"cannot detect Windows ProgramFiles path","messagePattern":"cannot detect Windows ProgramFiles path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/winsvc/path_windows.go","lineNumber":199,"sourceCode":"\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}\n\t\tw.ProgramFiles = strings.ReplaceAll(w.ProgramFiles, \"SystemDrive\", w.SystemDrive)\n\t})\n\n\treturn w.loadErr\n}\n","sourceCodeStart":181,"sourceCodeEnd":207,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/winsvc/path_windows.go#L181-L207","documentation":"The winsvc helper cannot determine the Windows ProgramFiles directory. It checks the ProgramFiles environment variable, then falls back to the registry value ProgramFilesDir under HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion. If both are empty it records this error in w.loadErr and stops, so path resolution for the library fails.","triggerScenarios":"Calling a path lookup that triggers the sync.Once loader when os.Getenv(\"ProgramFiles\") is empty and the registry GetStringvalue on 'ProgramFilesDir' fails or is empty.","commonSituations":"Service running under an account with a sanitized environment; minimal/modified Windows images missing the registry key; running in containers or emulated Windows where standard env vars are absent.","solutions":["Set the ProgramFiles environment variable (e.g. set ProgramFiles=C:\\Program Files) before the process starts.","Check and restore the registry value ProgramFilesDir under HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion.","Run under a standard Windows service environment so default system env vars are populated.","For custom images/containers, explicitly inject standard Windows environment variables at launch."],"exampleFix":"// before\nProgramFiles env empty, registry ProgramFilesDir missing -> loadErr\n\n// after\n# launch wrapper\nset ProgramFiles=C:\\Program Files","handlingStrategy":"validation","validationCode":"if runtime.GOOS == \"windows\" && os.Getenv(\"ProgramFiles\") == \"\" {\n    return errors.New(\"ProgramFiles env var missing; set it before use\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"cannot detect Windows ProgramFiles path\") {\n    // use fallback default C:\\\\Program Files or fail fast\n}","preventionTips":["Do not strip standard Windows environment variables in service wrappers.","Verify registry integrity (ProgramFilesDir) on golden images.","Test under the actual service account, not just an interactive shell."],"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"}