I worked with the Registry value with this code:
Include:
#include <windows.h>
To read:
QSettings setting( "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", QSettings::NativeFormat ); QString pathVal = setting.value("Path", "no-path").toString();
To write:
setting.setValue( "Path", path ); SendMessageA( HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment" );
Thus, I get the actual Path value without reloading the program and write the value that passes the change to all processes.
Failed to figure out how to use SendMessage from this answer:
How to change the PATH variable specifically through the command line in Windows .
I thought I should create a Win32 application in Visual Studio and then send this message inside it.
But this function should be called immediately after changing the registry. Therefore, I can manually change the registry value, and then click the button called SendMessageA and the Path updated.
By the way, there is a SendMessage macro that calls the SenMessageW function, but it does not work, and Path not changed. I donβt know what A means, but it changes the variable.
source share