User Path not working until computer restart
-
In my app I'm using JNI, and because of that I have to add into User/System Path the location to
jvm.dll
fromJRE\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 usingREG 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 astd::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 ; -
In my app I'm using JNI, and because of that I have to add into User/System Path the location to
jvm.dll
fromJRE\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 usingREG 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 astd::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 ;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. -
In my app I'm using JNI, and because of that I have to add into User/System Path the location to
jvm.dll
fromJRE\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 usingREG 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 astd::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 ;