生成系统环境变量
Code
procedure CreateEnvironment(const ALIBPath, AINCPath: string);
resourcestring
REG_C51_LIB = 'C51LIB';
REG_C51_INC = 'C51INC';
REG_PATH = 'PATH';
REG_MACHINE_LOCATION = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
REG_USER_LOCATION = 'Environment';
var
FPath: string;
function DataExits(const ASources, AData: string): Boolean;
var
FList: TStrings;
i: Integer;
begin
Result := False;
FList := Split(ASources, ';');
for i := 0 to FList.Count - 1 do
begin
if FList[i] = AData then Result := True;
end;
end;
begin
with TRegistry.Create do
begin
try
RootKey := HKEY_LOCAL_MACHINE;
OpenKey(REG_MACHINE_LOCATION, True);
FPath := ReadString(REG_PATH);
if not DataExits(FPath, ALIBPath)then
begin
FPath := ReadString(REG_PATH) + ALIBPath + ';';
WriteString(REG_PATH, FPath);
SetEnvironmentVariable(PChar(REG_C51_LIB), PChar(ALIBPath));
// SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, Integer(PChar('Environment')));
end;
FPath := ReadString(REG_PATH);
if not DataExits(FPath, AINCPath)then
begin
FPath := ReadString(REG_PATH) + AINCPath + ';';
WriteString(REG_PATH, FPath);
SetEnvironmentVariable(PChar(REG_C51_LIB), PChar(ALIBPath));
// SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, Integer(PChar('Environment')));
end;
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, Integer(PChar('Environment')));
finally
Free;
end;
end;
end;
procedure CreateEnvironment(const ALIBPath, AINCPath: string);
resourcestring
REG_C51_LIB = 'C51LIB';
REG_C51_INC = 'C51INC';
REG_PATH = 'PATH';
REG_MACHINE_LOCATION = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
REG_USER_LOCATION = 'Environment';
var
FPath: string;
function DataExits(const ASources, AData: string): Boolean;
var
FList: TStrings;
i: Integer;
begin
Result := False;
FList := Split(ASources, ';');
for i := 0 to FList.Count - 1 do
begin
if FList[i] = AData then Result := True;
end;
end;
begin
with TRegistry.Create do
begin
try
RootKey := HKEY_LOCAL_MACHINE;
OpenKey(REG_MACHINE_LOCATION, True);
FPath := ReadString(REG_PATH);
if not DataExits(FPath, ALIBPath)then
begin
FPath := ReadString(REG_PATH) + ALIBPath + ';';
WriteString(REG_PATH, FPath);
SetEnvironmentVariable(PChar(REG_C51_LIB), PChar(ALIBPath));
// SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, Integer(PChar('Environment')));
end;
FPath := ReadString(REG_PATH);
if not DataExits(FPath, AINCPath)then
begin
FPath := ReadString(REG_PATH) + AINCPath + ';';
WriteString(REG_PATH, FPath);
SetEnvironmentVariable(PChar(REG_C51_LIB), PChar(ALIBPath));
// SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, Integer(PChar('Environment')));
end;
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, Integer(PChar('Environment')));
finally
Free;
end;
end;
end;