1、安装程序可以使用 innosetup
2、如果想用代码实现:
////////////////////////////////////////////////////////////////////////////////
//设计: Linc 2003.10.11
//功能: 设置环境变量
//参数:
////////////////////////////////////////////////////////////////////////////////
procedure SetEnvironmentPath(const APath: string);
var
nPos, nSize, nLength: Integer;
strCurPath: string;
oReg: TRegistry;
begin
if SameText('', APath) then
Exit;
strCurPath := GetEnvironmentVariable(conEnviPathName);
nPos := Pos(APath, strCurPath);
nLength := Length(APath);
nSize :=Length(strCurPath);
if (nPos <> 0) and ((nPos + nLength = nSize + 1) or
(strCurPath[nPos + nLength] = conEnvironmentSplit)) then
Exit;
strCurPath := strCurPath + conEnvironmentSplit + APath;
oReg := TRegistry.Create;
with oRegdo
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(conRegEnviSubKey, False) then
begin
WriteString(conEnviPathName, strCurPath);
CloseKey;
SetEnvironmentVariable(conEnviPathName, Pchar(strCurPath));
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, Integer(Pchar(conEnvironment)));
end;
finally
Free;
end;
end;