Is it possible to add a directory to DLL search path from a batch file or cmd script?

matt wilkie picture matt wilkie · Feb 5, 2009 · Viewed 44.4k times · Source

MSDN says that the function SetDllDirectory() can be used to insert a directory into the DLL Search Path. Can this function be accessed from a batch file or cmd script, perhaps using via cscript?

The aim is to have our development version of a dll found before a pre-existing older one in %WINDIR% etc. without having to write a program just for that.

Thanks in advance for your time and thoughts.

Answer

Tron picture Tron · Feb 5, 2009

You can place the DLL in the same path as the executable, which is searched first before %WINDIR%. There's no way to call SetDllDirectory from a batch file directly.

But, you can insert your DLL directory in the %PATH% variable, and Windows will then find the DLL there.

set PATH=C:\path to your dll;%PATH%