Which Windows env var is responsible for DNS resolition?

Although, it isn't a pure Rust question, I simply do not know where to ask it. I asked from several AI engines with no success. Here is my code snippet:

let output = Command::new("git")
                                .arg("clone")
                                .arg("-o")
                                .arg(rep_name)
                                .arg(git_url)
                                .current_dir(real_dir.parent().ok_or("no parent directory")?)
                                .env(
                                    "HOME",
                                    config
                                        .to_real_path("", None)
                                        .ok_or("project path misconfiguration")?,
                                )
                                .output()?;
                            if output.status.success().not() {
                                ok = format!("Err:  {}", output.status)
                            }
                        
                            let stderr_str = String::from_utf8_lossy(&output.stderr);
                            if !stderr_str.trim().is_empty() && !stderr_str.starts_with("Cloning into") {
                                eprintln!("clonning err: {stderr_str}");
                                ok = format!("Err:  {stderr_str}");
                            }

It works flawlessly in Linux environment, however fails on Windows with a message: can't resolve github.com. I clear environment before the call, and for the reason I restore 'HOME' in Linux. If I pass a complete environment on Windows, the Rust code works as well. However, I do not want to do that for a security reason. I need only to locate one (maybe few more) env variable critical for DNS resolution on Windows?

How are you clearing environment variables? That's not shown in the above code.

I will make some notes though:

  • For Windows, HOME doesn't do anything. The Windows equivlent is USERPROFILE
  • At an absolute minimum, it's necessary to preserve the SystemRoot environment variable if you want system DLLs to work.

I modified my code upon your recommendation:

let mut cgi_env = if cgi {
        let mut env: HashMap<String, String> = if preserve_env {
            env::vars().collect()
        } else {
            #[cfg(unix)]
            {
                env::vars()
                    .filter(|(k, _)| k == "PATH" || k == "RUST_BACKTRACE")
                    .collect()
            }
            #[cfg(target_os = "windows")]
            {
                env::vars()
                    .filter(|(k, _)| k == "Path" || k == "RUST_BACKTRACE" || k == "SystemRoot")
                    .collect()
            }
        };

And clone is working now. I provided HOME just for illustration.