hashicorp/nomad · error

cannot detect Windows ProgramData path

Error message

cannot detect Windows ProgramData path

What it means

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.

Solutions

  1. Set the ProgramData environment variable (e.g. set ProgramData=C:\ProgramData) for the process/service account before starting the app.
  2. Verify the registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders contains a ProgramData value and repair it if missing.
  3. Run the process as a normal Windows service account under a standard Windows installation so the default environment/registry are present.
  4. If running in a container/emulator, mount or provide a valid ProgramData path in the environment.

Example fix

// before (no env, registry lookup fails)
w.ProgramData == "" -> cannot detect Windows ProgramData path

// after (deployment/launch fix)
# in service wrapper or container definition
set ProgramData=C:\ProgramData
Defensive patterns

Strategy: validation

Validate before calling

if runtime.GOOS == "windows" && os.Getenv("ProgramData") == "" {
    // probe or set before calling path helpers
    return errors.New("ProgramData env var missing; set it before use")
}

Try / catch

if err := winsvc.PathErr(); err != nil {
    if strings.Contains(err.Error(), "cannot detect Windows ProgramData path") {
        // fall back to a computed default or abort early
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at helper/winsvc/path_windows.go:183

		w.SystemDrive = os.Getenv("SystemDrive")
		if w.SystemDrive == "" {
			w.loadErr = fmt.Errorf("cannot detect Windows SystemDrive path")
			return
		}
		w.SystemRoot = strings.ReplaceAll(os.Getenv("SystemDrive"), "SystemDrive", w.SystemDrive)

		w.ProgramData = os.Getenv("ProgramData")
		if w.ProgramData == "" {
			pdKey, err := registry.OpenKey(registry.LOCAL_MACHINE,
				`SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList`, registry.QUERY_VALUE)
			if err == nil {
				if pdVal, _, err := pdKey.GetStringValue("ProgramData"); err == nil {
					w.ProgramData = pdVal
				}
			}
		}
		if w.ProgramData == "" {
			w.loadErr = fmt.Errorf("cannot detect Windows ProgramData path")
			return
		}
		w.ProgramData = strings.ReplaceAll(w.ProgramData, "SystemDrive", w.SystemDrive)

		w.ProgramFiles = os.Getenv("ProgramFiles")
		if w.ProgramFiles == "" {
			pdKey, err := registry.OpenKey(registry.LOCAL_MACHINE,
				`SOFTWARE\Microsoft\Windows\CurrentVersion`, registry.QUERY_VALUE)
			if err == nil {
				if pdVal, _, err := pdKey.GetStringValue("ProgramFilesDir"); err == nil {
					w.ProgramFiles = pdVal
				}
			}
		}
		if w.ProgramFiles == "" {
			w.loadErr = fmt.Errorf("cannot detect Windows ProgramFiles path")
			return
		}

View on GitHub (pinned to 482b49bf1a)