0

I am writing a program in c++ that adds a new directory to the path environment variable for the system. The directory is successfully added with the RegSetValueEx() function but the changes are not reflected for all processes.

I have tried BroadcastSystemMessage() and SendMessageTimeout() functions seperately as below

LPCTSTR keyPath = TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Environment");
        
BroadcastSystemMessage(0, 0, WM_SETTINGCHANGE, 0, (LPARAM)keyPath); 

and

LPCTSTR keyPath = TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Environment");

SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)keyPath, SMTO_BLOCK, 100, NULL); 

but they both dont work, however when i restart my system the changes are then reflected.

What i want

I want the changes to be reflected for all process without logout and it is possible as few days ago i installed a software (Composer https://getcomposer.org) that added its environment path and refreshed the environment variables for all processes without requiring a system restart.

Here are some useful links i have already viewed

Huzaifa
  • 161
  • 1
  • 10
  • 3
    All those functions do is send a message to all applications notifying them that a setting has changed. If some applications choose to ignore that message there isn't much you can do. I find it unlikely that one application would be able to force an environment change on another application. That seems like a security flaw. – john Aug 23 '20 at 18:26
  • My bad, i was using the function incorrectly. – Huzaifa Aug 24 '20 at 07:41

1 Answers1

0

I figured out what i was doing wrong, I was using

LPCTSTR keyPath = TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Environment");
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)keyPath, SMTO_BLOCK, 100, NULL); 

when it should be

LPCTSTR keyPath = TEXT("Environment");
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)keyPath, SMTO_BLOCK, 100, NULL);

and this refreshed the environment variables for other processes without a restart.

Huzaifa
  • 161
  • 1
  • 10