prototype LONG User32.SendMessageTimeout(HWND,LONG,LONG,LONG,LONG,LONG,LONG);
//The SetEnvironmentVariable function sets the contents of the specified environment variable for the current process.
//This function has no effect on the system environment variables or the environment variables of other processes.
prototype BOOL KERNEL32.SetEnvironmentVariable(BYVAL STRING,BYVAL STRING);
#define WM_SETTINGCHANGE 0x1A
#define SMTO_ABORTIFHUNG 0x2
prototype UpdateSystemPath(BOOL);
function UpdateSystemPath(bAdd)
NUMBER nRootKey, nResult, nvSize, nvType;
POINTER pParam, pResult;
LONG lResult;
STRING szParam, szPath, szWinDir;
begin
Disable(LOGGING);
nRootKey = HKEY_LOCAL_MACHINE;
if RegDBSetDefaultRoot(nRootKey) = 0 then
nvSize = 1;
nvType = REGDB_STRING;
nResult = RegDBGetKeyValueEx("SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment", "Path", nvType, szPath, nvSize);
szWinDir = WINDIR;
StrRemoveLastSlash(szWinDir);
StrReplace(szPath, "%SystemRoot%", szWinDir, 0);
PathSet(szPath);
if bAdd then
PathAdd(TARGETDIR ^ "Bin", "", FULL, AFTER);
else
PathDelete(TARGETDIR ^ "Bin", FULL);
endif;
PathGet(szPath);
RegDBSetKeyValueEx("SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment", "Path", REGDB_STRING, szPath, -1);
szParam = "Environment";
pParam = &szParam;
pResult = &lResult;
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, pParam, SMTO_ABORTIFHUNG, 100, pResult);
//set environment variable for current process
SetEnvironmentVariable("PATH",szPath);
endif;
Enable(LOGGING);
end;