5

I am having a weird problem with the PATH variable under windows:

My application is in a folder c:\app\bin and the DLLs for this application are in the c:\app\runtime folder. To run my program I modify the PATH variable with a *.bat file usually with the following script:

set PATH="c:\app\bin";"c:\app\runtime";%PATH%

This will bring the executables and the DLLs on the path. However, on one of my Windows Server 2008 R2 systems this does not work. That means, if I execute the above command in a command window, I can start the exe file from c:\app\bin, but the application complains immediately that it cannot find some dll files required ("The program can't start because ....dll is missing from your computer ..."). These dll files should be in c:\app\runtime.

I experimented a little bit and it points out that there are three workarounds:

  1. Modify the PATH variable permanently using the System Properties dialog
  2. Omit the quotation marks in the above command for the path of the DLL files, e.g. set PATH="c:\app\bin";c:\app\runtime;%PATH%
  3. Copying the DLL files to the directory where the exe is located

The weird part about solution 2 is, that it does not change anyhing if I add quotation marks to the first path, or if I change the order of the paths.

Has someone a clue why my original script does not work? I need to get it run, because it is created automatically by a program and I cannot change the application that generates the bat file.

Heinrich
  • 900
  • 5
  • 21
  • 35
  • The preferred solution is to put the executable and the DLLs in the same directory. – Harry Johnston Jan 13 '12 at 04:17
  • No, this cannot be a solution and it does not make sense – Heinrich Jan 16 '12 at 10:42
  • Why doesn't it make sense? The directory in which the executable is located is the very first place the system looks for DLLs, which makes it the most logical place to put them, unless they are shared by multiple applications in which case you should be using manifests. – Harry Johnston Jan 16 '12 at 20:16
  • OK, so you can't fix the error in the .bat file, and you can't move the DLLs. Can you modify the executable itself? – Harry Johnston Jan 16 '12 at 20:18

2 Answers2

8

The PATH variable doesn't ordinarily contain quotes; it uses semicolons as its delimiter. For example, here is my system's PATH definition, which includes folders with spaces:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft Windows Performance Toolkit\

It seems that Windows can execute programs with "quoted" paths, but the DLL search routine can't handle them.

Ideally you should use:

set PATH=c:\app\bin;c:\app\runtime;%PATH%

Another workaround might be to launch the program from c:\app\runtime, eg:

cd /d C:\app\runtime
..\bin\app.exe

That may not even require modifying the PATH variable.

fission
  • 3,601
  • 2
  • 21
  • 31
  • 1
    +1, but note that the workaround you mention may be disabled, see http://support.microsoft.com/kb/2264107 – Harry Johnston Jan 13 '12 at 04:17
  • What does this tell me? – Heinrich Jan 13 '12 at 12:13
  • 1
    The last part of my answer essentially sets the _working directory_ to `C:\app\runtime`; the working directory is normally also searched for DLLs. The article Harry mentions describes a method to disable that behaviour, so that the working directory isn't searched for DLLs. Thus in some (probably rare) cases that workaround won't work, due to a non-default policy set by the system administrator. – fission Jan 15 '12 at 05:57
  • Thanks fission. My comment was related to the link of Harry. – Heinrich Jan 16 '12 at 20:32
  • So was mine! :-) – fission Jan 16 '12 at 21:12
1

This happens when you paste in a path value with TWO or more paths separated by a COLON instead of pasting them into the dialog one at a time. I had the same issue.

Your Solutions:

  1. Remove the path value with separated by COLONS and paste them into a text editor, then paste each path value in separately. OR
  2. Click the button EDIT TEXT... and remove the quotes around the outside of your string. The environment var dialog will then move each value to a new line.

Click OK OK then relaunch your terminal editor to load the new values.

Hope that helps!

Dr Tyrell
  • 111
  • 2