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.
To clear up dispute on the dll search order (in the comments on @jussij's answer), here's the list, drawn from Microsoft's doc:
If
SafeDllSearchMode
is enabled, the search order is as follows:GetSystemDirectory
function to get the path of this directory.GetWindowsDirectory
function to get the path of this directory.If
SafeDllSearchMode
is disabled, the search order is as follows:GetSystemDirectory
function to get the path of this directory.GetWindowsDirectory
function to get the path of this directory.See http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx#standard_search_order_for_desktop_applications
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.
If the DLL is not in the same folder as the executable Windows will search for the file in the folders specified in the system path. So all you need to do is put your folder at the start of the path.
You can do this using the following batch command:
If your path contains white space you need to use the following batch command:
But remember this path change is only made to the PATH of the current console session. If you close and reopen the console these path changes will be lost.