diff --git a/SystemTools.cxx b/SystemTools.cxx
index 44be545111a11cfe4f83aa15d5b1416d7b87fa82..37fe421992aca4d166551220609d36a5089cb77c 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -2970,6 +2970,8 @@ std::string SystemTools::FindProgram(
   bool no_system_path)
 {
   std::vector<std::string> extensions;
+  std::string tryPath;
+
 #if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
   bool hasExtension = false;
   // check to see if the name already has a .xxx at
@@ -2983,22 +2985,22 @@ std::string SystemTools::FindProgram(
     {
     extensions.push_back(".com");
     extensions.push_back(".exe");
-    }
-#endif
-  std::string tryPath;
 
-  // first try with extensions if the os supports them
-  for(std::vector<std::string>::iterator i =
-        extensions.begin(); i != extensions.end(); ++i)
-    {
-    tryPath = name;
-    tryPath += *i;
-    if(SystemTools::FileExists(tryPath) &&
-        !SystemTools::FileIsDirectory(tryPath))
+    // first try with extensions if the os supports them
+    for(std::vector<std::string>::iterator i =
+          extensions.begin(); i != extensions.end(); ++i)
       {
-      return SystemTools::CollapseFullPath(tryPath);
+      tryPath = name;
+      tryPath += *i;
+      if(SystemTools::FileExists(tryPath) &&
+          !SystemTools::FileIsDirectory(tryPath))
+        {
+        return SystemTools::CollapseFullPath(tryPath);
+        }
       }
     }
+#endif
+
   // now try just the name
   tryPath = name;
   if(SystemTools::FileExists(tryPath) &&