我在做一个Delphi7的绿色版,用Inno setup 来做了一个绿化注册程序(初学),想在注册的时候把delphi的目录添加到系统环境变量path中,不重启立即生效.倒是找到相关的代码,不过是delphi的,没法在inno setup script中运行. 特请教对Inno setup script 熟悉的达人.
下面是我的CODE段代码:var
FRootDir: string;
procedure _SetDelphiPath(aIsInstall: Boolean);
var
S_Path, s: string;
S1: string;
begin
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', S_Path) then
begin
if aIsInstall then
S1 := ExpandConstant('{src}\bin')
else
S1 := FRootDir + '\bin'; if pos(Uppercase(S1), Uppercase(S_Path)) = 0 then //还没有加入
begin
if aIsInstall then
begin
S_Path := S_Path + ';' + S1;
end;
end else
if not aIsInstall then
begin
StringChangeEx(S_Path, S1 + ';', '', True);
StringChangeEx(S_Path, S1, '', True);
end; if aIsInstall then
S1 := ExpandConstant('{src}\Projects\bpl')
else
S1 := FRootDir + '\Projects\bpl'; if pos(Uppercase(S1), Uppercase(S_Path)) = 0 then //还没有加入
begin
if aIsInstall then
begin
S_Path := S_Path + ';' + S1;
end;
end else
if not aIsInstall then
begin
StringChangeEx(S_Path, S1 + ';', '', True);
StringChangeEx(S_Path, S1, '', True);
end; RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', S_Path);
end;
end;procedure DeinitializeUninstall();
begin
_SetDelphiPath(False);
end;procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
FIsExists := False;
if CurUninstallStep = usUninstall then
begin
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Borland\Delphi\7.0', 'RootDir', FRootDir) then
begin
StringChangeEx(FRootDir, '\\', '\', True);
FRootDir := RemoveBackslash(FRootDir);
end;
end;
end;procedure CurPageChanged(CurPageID: Integer);
var
SL: TStringList;
S1: string;
begin
if CurPageID = wpFinished then
begin
_SetDelphiPath(True);
//关键问题在下面的代码如何实现?
//SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,Integer(Pchar('Environment')));
//这是我找到的delphi里的方法,在inno setup script里该怎么写?或是有其它的方法?
end;
end;
下面是我的CODE段代码:var
FRootDir: string;
procedure _SetDelphiPath(aIsInstall: Boolean);
var
S_Path, s: string;
S1: string;
begin
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', S_Path) then
begin
if aIsInstall then
S1 := ExpandConstant('{src}\bin')
else
S1 := FRootDir + '\bin'; if pos(Uppercase(S1), Uppercase(S_Path)) = 0 then //还没有加入
begin
if aIsInstall then
begin
S_Path := S_Path + ';' + S1;
end;
end else
if not aIsInstall then
begin
StringChangeEx(S_Path, S1 + ';', '', True);
StringChangeEx(S_Path, S1, '', True);
end; if aIsInstall then
S1 := ExpandConstant('{src}\Projects\bpl')
else
S1 := FRootDir + '\Projects\bpl'; if pos(Uppercase(S1), Uppercase(S_Path)) = 0 then //还没有加入
begin
if aIsInstall then
begin
S_Path := S_Path + ';' + S1;
end;
end else
if not aIsInstall then
begin
StringChangeEx(S_Path, S1 + ';', '', True);
StringChangeEx(S_Path, S1, '', True);
end; RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', S_Path);
end;
end;procedure DeinitializeUninstall();
begin
_SetDelphiPath(False);
end;procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
FIsExists := False;
if CurUninstallStep = usUninstall then
begin
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Borland\Delphi\7.0', 'RootDir', FRootDir) then
begin
StringChangeEx(FRootDir, '\\', '\', True);
FRootDir := RemoveBackslash(FRootDir);
end;
end;
end;procedure CurPageChanged(CurPageID: Integer);
var
SL: TStringList;
S1: string;
begin
if CurPageID = wpFinished then
begin
_SetDelphiPath(True);
//关键问题在下面的代码如何实现?
//SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,Integer(Pchar('Environment')));
//这是我找到的delphi里的方法,在inno setup script里该怎么写?或是有其它的方法?
end;
end;
Inno setup 肯定是能做到的,因为Delphi 7 Second Edition v7.2安装程序也是用它做的,它的安装完成后系统变量就立即生效了,但没它的inno script,不知是如何做的.
没试过这样使用!顶一顶,有机会验证一下看看.
建议楼主去找一份InnoSetUp的源代码把里面相应的部分修改一下,改成自己需要支持的脚本功能啊.
正确的方法
设置ChangesEnvironment后,需要在正确的事件中调用,安装时需要在以下调用procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
_SetDelphiPath(True);end;
卸载时需要在以下调用:
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then
begin
_SetDelphiPath(False);
end;
end;之前的
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpFinished then
.....
调用时inno已经通知刷新系统变量了,所以不起作用.要在通知刷新之前调用,经过试验前面两个事件时机结果正确.
http://legroom.net/software/modpath