diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index 93a99b7a01ae422ee4fc4653dc5e95afc45fbef2..c852c493f702bf1b0163fc3257fe24707e49a8c5 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -100,19 +100,21 @@ static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
 static void addGmshPathToEnvironmentVar(const std::string &name)
 {
   std::string gmshPath = SplitFileName(GetExecutableName(CTX::instance()->argv0))[0];
-  std::string path;
-  char *tmp = getenv(name.c_str());
-  if(tmp){
-    path = tmp;
+  if(gmshPath.size()){
+    std::string path;
+    char *tmp = getenv(name.c_str());
+    if(tmp){
+      path = tmp;
 #if defined(WIN32)
-    path += ";" + gmshPath;
+      path += ";" + gmshPath;
 #else
-    path += ":" + gmshPath;
+      path += ":" + gmshPath;
 #endif
+    }
+    else
+      path = gmshPath;
+    SetEnvironmentVar(name.c_str(), path.c_str());
   }
-  else
-    path = gmshPath;
-  SetEnvironmentVar(name.c_str(), path.c_str());
 }
 
 void Msg::Init(int argc, char **argv)
diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp
index a170097481b95634e5c54112ec11a93d1dd2897d..0826d910edb227b46a890d61613fdcf670ee92cd 100644
--- a/Fltk/onelabGroup.cpp
+++ b/Fltk/onelabGroup.cpp
@@ -253,13 +253,13 @@ static void onelab_choose_executable_cb(Fl_Widget *w, void *data)
 
     // try to find an executable automatically (this is really useful for
     // beginners)
-    if(CTX::instance()->argv0.size()){
-      std::vector<std::string> split = SplitFileName(CTX::instance()->argv0);
+    std::string gmshPath = SplitFileName(GetExecutableName(CTX::instance()->argv0))[0];
+    if(gmshPath.size()){
       std::string name = c->getName();
       for(unsigned int i = 0; i < name.size(); i++)
         name[i] = tolower(name[i]);
-      std::string path1 = split[0] + name;
-      std::string path2 = split[0] + "data/" + name;
+      std::string path1 = gmshPath + name;
+      std::string path2 = gmshPath + "data/" + name;
 #if defined(WIN32)
       path1 += ".exe";
       path2 += ".exe";