Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. User Path not working until computer restart

User Path not working until computer restart

Scheduled Pinned Locked Moved Java
helpjavapythonsysadmindata-structures
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Valentinor
    wrote on last edited by
    #1

    In my app I'm using JNI, and because of that I have to add into User/System Path the location to jvm.dll from JRE\bin\server. To add a variable in User Path it doesn't require administrator rights, so I'm taking this approach. To add it I'm using REG ADD from CMD with the following functions. The problem that I have is that after I'm adding the variable into Path, the software still doesn't see it and returns the error "jvm.dll not found", but if I restart the computer, then it runs fine and sees the variable. Also after I'm adding it, if I manually go into User Path and double click to edit the variable, and simply press enter without changing anything, then it doesn't require the restart. Does it have something to do with the code/way I'm adding the variable? What should I do to get past this and to get it working without the user/client having to restart the computer before it is working? Function to run CMD:

    std::string executeCMD(const char* cmd) {
    std::string result;
    std::array buffer;
    std::unique_ptr pipe(_popen(cmd, "r"), _pclose);
    if (!pipe) {
    return "ErrorCMD";
    }
    while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
    result += buffer.data();
    }
    return result;
    }

    Use of the function:

    resultCMD.insert(0, "reg add \"HKEY_CURRENT_USER\\Environment\" /v PATH /t REG_EXPAND_SZ /d \"");
    resultCMD.append("\" /f");
    executeCMD(resultCMD.c_str());

    resultCMD is a std::string which contains the values that were in Path and also the value that I'm adding under the following format with "C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server" being added after I use the function from above: C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server;D:\Program Files (x86)\VMware\VMware Player\bin\;D:\Program Files\Python\Python310\Scripts\;D:\Program Files\Python\Python310\;C:\Windows\system32;C:\Windows; ...and the rest of the variables, this was as an example, after each variable they have a ;

    V E 2 Replies Last reply
    0
    • V Valentinor

      In my app I'm using JNI, and because of that I have to add into User/System Path the location to jvm.dll from JRE\bin\server. To add a variable in User Path it doesn't require administrator rights, so I'm taking this approach. To add it I'm using REG ADD from CMD with the following functions. The problem that I have is that after I'm adding the variable into Path, the software still doesn't see it and returns the error "jvm.dll not found", but if I restart the computer, then it runs fine and sees the variable. Also after I'm adding it, if I manually go into User Path and double click to edit the variable, and simply press enter without changing anything, then it doesn't require the restart. Does it have something to do with the code/way I'm adding the variable? What should I do to get past this and to get it working without the user/client having to restart the computer before it is working? Function to run CMD:

      std::string executeCMD(const char* cmd) {
      std::string result;
      std::array buffer;
      std::unique_ptr pipe(_popen(cmd, "r"), _pclose);
      if (!pipe) {
      return "ErrorCMD";
      }
      while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
      result += buffer.data();
      }
      return result;
      }

      Use of the function:

      resultCMD.insert(0, "reg add \"HKEY_CURRENT_USER\\Environment\" /v PATH /t REG_EXPAND_SZ /d \"");
      resultCMD.append("\" /f");
      executeCMD(resultCMD.c_str());

      resultCMD is a std::string which contains the values that were in Path and also the value that I'm adding under the following format with "C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server" being added after I use the function from above: C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server;D:\Program Files (x86)\VMware\VMware Player\bin\;D:\Program Files\Python\Python310\Scripts\;D:\Program Files\Python\Python310\;C:\Windows\system32;C:\Windows; ...and the rest of the variables, this was as an example, after each variable they have a ;

      V Offline
      V Offline
      Valentinor
      wrote on last edited by
      #2

      I ended up switching to use RegOpenKeyExA, RegQueryValueExA, RegCreateKeyEx, RegSetValueExA to get and add the values into Path, that way I can use SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)TEXT("Environment")); to get past the need for a system restart/logout.

      1 Reply Last reply
      0
      • V Valentinor

        In my app I'm using JNI, and because of that I have to add into User/System Path the location to jvm.dll from JRE\bin\server. To add a variable in User Path it doesn't require administrator rights, so I'm taking this approach. To add it I'm using REG ADD from CMD with the following functions. The problem that I have is that after I'm adding the variable into Path, the software still doesn't see it and returns the error "jvm.dll not found", but if I restart the computer, then it runs fine and sees the variable. Also after I'm adding it, if I manually go into User Path and double click to edit the variable, and simply press enter without changing anything, then it doesn't require the restart. Does it have something to do with the code/way I'm adding the variable? What should I do to get past this and to get it working without the user/client having to restart the computer before it is working? Function to run CMD:

        std::string executeCMD(const char* cmd) {
        std::string result;
        std::array buffer;
        std::unique_ptr pipe(_popen(cmd, "r"), _pclose);
        if (!pipe) {
        return "ErrorCMD";
        }
        while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
        result += buffer.data();
        }
        return result;
        }

        Use of the function:

        resultCMD.insert(0, "reg add \"HKEY_CURRENT_USER\\Environment\" /v PATH /t REG_EXPAND_SZ /d \"");
        resultCMD.append("\" /f");
        executeCMD(resultCMD.c_str());

        resultCMD is a std::string which contains the values that were in Path and also the value that I'm adding under the following format with "C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server" being added after I use the function from above: C:\Program Files\Eclipse Adoptium\jre-18.0.1.10-hotspot\bin\server;D:\Program Files (x86)\VMware\VMware Player\bin\;D:\Program Files\Python\Python310\Scripts\;D:\Program Files\Python\Python310\;C:\Windows\system32;C:\Windows; ...and the rest of the variables, this was as an example, after each variable they have a ;

        E Offline
        E Offline
        englebart
        wrote on last edited by
        #3

        There is also the “setx” command that can help with that. I ran into similar problems setting info into the registry directly.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups