Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
The preferred solution is to put the executable and the DLLs in the same directory. –  Harry Johnston Jan 13 '12 at 4: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
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
+1, but note that the workaround you mention may be disabled, see support.microsoft.com/kb/2264107 –  Harry Johnston Jan 13 '12 at 4: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 5: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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.