Puzzling out why a program doesn’t work when run from a batch file, but works when double-clicked from Explorer
cppdashboard.dev/r/2026/10/puzzling-out-why-a-program-doesn-t-work-when-run-from-a-batcThis article discusses a common issue where a program fails to run correctly from a batch file due to the current directory not being set properly. It explains how double-clicking a program in Explorer sets the current directory, which can affect how the program locates ancillary files.
From the article
A customer asked for help writing a batch file to launch a program. For some reason, the program displayed an error message when the batch file ran it, whereas it worked fine when they double-clicked the program from Explorer.
I immediately suspected that they were not setting the current directory.
Some time ago, I noted that when you double-click a file in Explorer, Explorer sets the current directory of the program to the directory containing the thing that you double-clicked . This is done to accomodate programs that look for ancillary files in the current directory. The example I had was a hypothetical LitWare Writer program that, when given an ABC.LIT file, looks for related files like ABC.LTC (the table of contents) and ABC.LDC (the custom dictionary) in the current directory.
Share this resource