title: Set Windows System Variables with Java
body: <p>is there a way to add a specific directory to the Windows systemvariable %PATH%?
  This doesn't seem to work:</p>
  
  <pre><code>String[] cmd = { "cmd", "/c", "set", "PATH=\"%PATH%;c:\\test\"" };
  Runtime.getRuntime().exec( cmd );
  </code></pre>
  
  <p>c:\test\ doesn't appear in System.getenv("PATH"); or in the output of </p>
  
  <pre><code>String[] cmd = { "cmd", "/c", "echo", "%PATH%" };
  Runtime.getRuntime().exec( cmd );
  </code></pre>
  
  <p>What I need is to modify the %PATH%-variable for the current Java-Process under Windows. The reason is, that I need to load some native dll-files which cross-reference each other. So I'd like to add the application-path to the Windows environment.</p>
  
  <p>The next thing I tried was a small JNI-Wrapper for the C-Function "putenv" which looks like this:</p>
  
  <pre><code>JNIEXPORT void JNICALL Java_com_splitscreen_AppletTest_PutEnv_putEnv
    (JNIEnv *env, jobject jobj, jstring val) {
  
      jboolean iscopy;
  
      const char *mvalue = (*env)-&gt;GetStringUTFChars(
                  env, val, &amp;iscopy);
  
      putenv(mvalue);
  }
  </code></pre>
  
  <p>This is how I call it:</p>
  
  <pre><code>final String curPath = System.getenv( "PATH" );
  final PutEnv pe = new PutEnv();
  pe.putEnv( "PATH=" + curPath + ";c:\test" );
  
  final String newPath = System.getenv( "PATH" );
  System.out.println( newPath );
  </code></pre>
  
  <p>But the pathes are equal. I'm not sure whether the Map of the Java-System-Environment isn't updated or whether putenv didn't work. Is there a way to check this?</p>