{*********************************************}
{ Set Global Environment Function }
{ Coder : Kingron,2002.8.6 }
{ Bug Report : Kingron@163.net }
{ Test OK For Windows 2000 Advance Server }
{ Parameter: }
{ Name : The environment name }
{ Value: The environment Value }
{ Ex: SetGlobalEnvironment('MyVar','OK') }
{*********************************************}
function SetGlobalEnvironment(const Name,Value:string):boolean;
const
REG_LOCATION='System/CurrentControlSet/Control/Session Manager/Environment';
var
R:DWORD;
begin
with TRegistry.Create do
try
RootKey :=HKEY_LOCAL_MACHINE;
Result :=OpenKey(REG_LOCATION,True);
if Result then
begin
WriteString(Name,Value);
SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,integer(Pchar('Environment')));
// SendMessageTimeOut(HWND_BROADCAST,WM_SETTINGCHANGE,0,integer(Pchar('Environment')),SMTO_NORMAL,1000,R);
end;
finally
Free;
end;
end;
{ Set Global Environment Function }
{ Coder : Kingron,2002.8.6 }
{ Bug Report : Kingron@163.net }
{ Test OK For Windows 2000 Advance Server }
{ Parameter: }
{ Name : The environment name }
{ Value: The environment Value }
{ Ex: SetGlobalEnvironment('MyVar','OK') }
{*********************************************}
function SetGlobalEnvironment(const Name,Value:string):boolean;
const
REG_LOCATION='System/CurrentControlSet/Control/Session Manager/Environment';
var
R:DWORD;
begin
with TRegistry.Create do
try
RootKey :=HKEY_LOCAL_MACHINE;
Result :=OpenKey(REG_LOCATION,True);
if Result then
begin
WriteString(Name,Value);
SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,integer(Pchar('Environment')));
// SendMessageTimeOut(HWND_BROADCAST,WM_SETTINGCHANGE,0,integer(Pchar('Environment')),SMTO_NORMAL,1000,R);
end;
finally
Free;
end;
end;