vectordotdev/vector · error

%ProgramFiles% environment variable must be defined

Error message

%ProgramFiles% environment variable must be defined

What it means

On Windows, Vector's default config path is derived from the %ProgramFiles% environment variable: std::env::var("ProgramFiles").expect("%ProgramFiles% environment variable must be defined") (src/config/loading/mod.rs). This Windows-only code runs when no --config is given and default discovery kicks in; if the environment lacks ProgramFiles (normally set by Windows as a system variable), startup panics while computing the default path.

Source

Thrown at src/config/loading/mod.rs:357

pub fn load<R: std::io::Read, T>(input: R, format: Format) -> Result<T, Vec<String>>
where
    T: serde::de::DeserializeOwned,
{
    // Via configurations that load from raw string, skip interpolation of env
    let with_vars = prepare_input(input, false)?;

    representation::deserialize_config(&with_vars, format)
}

#[cfg(not(windows))]
fn default_path() -> PathBuf {
    "/etc/vector/vector.yaml".into()
}

#[cfg(windows)]
fn default_path() -> PathBuf {
    let program_files =
        std::env::var("ProgramFiles").expect("%ProgramFiles% environment variable must be defined");
    format!("{}\\Vector\\config\\vector.yaml", program_files).into()
}

fn default_config_paths() -> Vec<ConfigPath> {
    #[cfg(not(windows))]
    let default_path = default_path();
    #[cfg(windows)]
    let default_path = default_path();

    vec![ConfigPath::File(default_path, Some(Format::Yaml))]
}

View on GitHub (pinned to 3708c39b12)

Solutions

  1. Pass the config path explicitly so default_path() is never consulted: vector --config C:\\Vector\\config\\vector.yaml (also set the Windows service binPath arguments)
  2. Restore the system variable in the launching environment: setx ProgramFiles "C:\\Program Files" /M (admin) or set it in the service wrapper's environment
  3. If using sanitized envs by design, export ProgramFiles yourself before launching vector.exe
  4. For the service install, reinstall via vector service install which registers proper arguments including the config path

Example fix

rem before (no config given, stripped environment)
vector

rem after (explicit config path, no env dependency)
vector --config C:\Vector\config\vector.yaml
Defensive patterns

Strategy: validation

Validate before calling

// Windows: check the variable before launching without an explicit config
#[cfg(windows)]
fn can_use_default_path() -> bool {
    std::env::var("ProgramFiles").is_ok()
}

Prevention

When it happens

Trigger: Running vector.exe with no -c/--config/VECTOR_CONFIG on Windows under an environment where ProgramFiles was stripped — cleared env blocks, some service wrappers/Job schedulers, minimal containers (Windows Server containers), ssh sessions with sanitized environments, or processes spawned with env -i.

Common situations: Running Vector as a Windows service or scheduled task whose environment block omits system variables; CI runners that sanitize env; Windows containers with deliberately minimal images; scripts that clear the environment before exec.

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 vectordotdev/vector@3708c39b12 (2026-08-20). Data as JSON: /api/errors/286a648e24c6346c. Report an issue: GitHub.