系统环境变量的设置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 }
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 }
相关文章推荐
- 系统环境变量的设置Delphi函数
- Delphi 中相对路径与绝对路径、系统环境变量等相关函数说明
- Delphi 中相对路径与绝对路径、系统环境变量等相关函数说明
- windows环境变量管理工具EnvMan!和系统自带环境变量设置工具say byebye
- Linux 环境变量知识大全之二——系统环境变量的设置
- QT的pro文件编写,高效简洁,,路径设置 有空格 引入系统环境变量等
- 由于系统环境变量的设置导致调用链接器出错
- 设置系统环境变量
- 第四章 设置LFS临时系统的环境变量
- 设置的系统环境变量不成功 MAC
- 命令行设置系统环境变量
- Windows系统设置环境变量后无需重启系统即可让变量生效的解决办法
- java 获取系统变量(环境变量和设置变量)
- R语言环境变量的设置 环境设置函数为options()
- Ubuntu 系统中设置环境变量 PATH 的方法
- bat批处理设置Java JDK系统环境变量文件
- 系统环境变量设置之后让其立即生效的办法
- java调用bat文件判断系统是32还是64位,并设置环境变量
- 系统环境变量的设置
- mac 系统环境变量设置