您的位置:首页 > 编程语言 > Delphi

系统环境变量的设置Delphi函数

2007-03-02 17:33 309 查看
uses TRegistry;

function SetGlobalEnvironment(const Name, Value: string;
const User: Boolean = True): Boolean;
resourcestring
REG_MACHINE_LOCATION = 'System/CurrentControlSet/Control/Session Manager/Environment';
REG_USER_LOCATION = 'Environment';
begin
with TRegistry.Create do
try
if User then { User Environment Variable }
Result := OpenKey(REG_USER_LOCATION, True)
else { System Environment Variable }
begin
RootKey := HKEY_LOCAL_MACHINE;
Result := OpenKey(REG_MACHINE_LOCATION, True);
end;
if Result then
begin
WriteString(Name, Value); { Write Registry for Global Environment }
{ Update Current Process Environment Variable }
SetEnvironmentVariable(PChar(Name), PChar(Value));
{ Send Message To All Top Window for Refresh }
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, Integer(PChar('Environment')));
end;
finally
Free;
end;
end; { SetGlobalEnvironment }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: