Windows Explorer sets current directory on double-click, batch files don't
A developer reported that a program failed with an error when launched from a batch file but ran fine when double-clicked in Windows Explorer. Microsoft's Raymond Chen explained that Explorer automatically sets the current working directory to the folder containing the launched file, while a batch file calling the program by full path does not change the directory at all. The customer fixed the issue by using pushd and popd commands to set and restore the working directory within the batch file.
GoKawiil's interpretation of the reporting above, not reported fact.
The explanation highlights a subtle but common pitfall in Windows scripting: programs that rely on finding ancillary files relative to the current directory can break silently depending on how they are launched. This suggests developers writing batch files or automation scripts should explicitly manage working directories rather than assume Explorer-like behavior.
- Explorer sets a program's current directory to match the launched file's folder, but batch files do not do this automatically.
- Programs that look for supporting files relative to the current directory can fail when launched differently.
- Using pushd/popd in batch files can correctly set and restore the working directory to avoid such errors.
Source: devblogs.microsoft.com — Raymond Chen, 2026-10-26
Published there as: “Why a program doesn't work when run from a batch file, but works when clicked”
Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.