Created
October 11, 2018 11:29
-
-
Save ericlaw1979/f21aa088a1a9d4c48d49bc6eef890314 to your computer and use it in GitHub Desktop.
If the system PATH environment variable changes, we need to call an undocumented Windows Shell function to rebuild our own Environment block such that new consoles/apps we spawn will see the new PATH.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add to the Private section of your main form's type declaration. | |
Procedure WMSettingChange(Var MSG: TMessage); MESSAGE WM_SETTINGCHANGE; | |
// If the system PATH environment variable changes, we need to call an | |
// undocumented Windows Shell function to rebuild our own Environment | |
// block such that new consoles/apps we spawn will see the new PATH. | |
Procedure TMain.WMSettingChange(Var MSG: TMessage); | |
var hLib: THandle; | |
pfnRegenerate: Function (oldEnv: Pointer; regenCurrent: BOOL): BOOL; StdCall; | |
pNil: Pointer; | |
Begin | |
if (MSG.LParam = 0) then Exit; | |
OutputDebugString(PChar(Format('WM_SettingChange in area "%s"', [PChar(MSG.LParam)]))); | |
if (0 <> StrComp(PChar('Environment'), PChar(MSG.LParam))) then Exit; | |
hLib := LoadLibraryEx('shell32.dll', 0, 0); | |
if (hLib = 0) then Exit; | |
pfnRegenerate := GetProcAddress(hLib, 'RegenerateUserEnvironment'); | |
if (Assigned(pfnRegenerate)) then | |
Begin | |
pNil := nil; | |
pfnRegenerate (@pNil, true); | |
OutputDebugString('SlickRun Process Environment Block updated.'); | |
End; | |
FreeLibrary(hLib); | |
End; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment