I worked with the Registry
value using 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" );
This way I get the actual Path
value without reloading the program and write the value broadcasting the change to all processes.
Couldn't realize first how to use SendMessage
from this answer:
How to modify the PATH variable definitely through the command line in Windows.
I thought I should create a Win32
app in Visual Studio and then send this message inside of it.
But this function should be called just after the registry changed. So I could edit the registry value manually and then press a button which called the SendMessageA
and the Path
updated.
BTW, there is SendMessage
macro which calls SenMessageW
function but it didn't work and the Path
didn't change. Don't know what the A
means but it changes the variable.