请问Inno setup script 中用CODE中函数修改windows 系统环境变量后如何立即生效?(100分)

D

dejoy

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做一个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);


[blue]//问题在下面的代码如何实现:
//SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,Integer(Pchar('Environment')));
//这是我找到的delphi里的方法,在inno setup script里该怎么写?或是有其它的方法?[/blue]
end;
end;

inno setup 中貌似有一个ChangesEnvironment属性,已经设为true,不过似乎不起作用,新建一个DOS窗口后查看Path还是没添加的.
Inno setup 肯定是能做到的,因为Delphi 7 Second Edition v7.2安装程序也是用它做的,它的安装完成后系统变量就立即生效了,但没它的inno script,不知是如何做的.
 

风铃夜思雨

Unregistered / Unconfirmed
GUEST, unregistred user!
关键是这一句,pascal不支持的
Integer(Pchar('Environment'))

不过现有的版本我想不出办法,但我今天编译出来的inno setup版本就可以了,但还没发布
 
D

dejoy

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢,已解决,不用重新编译的版本.自己编译很麻烦吧? 貌似原版都不支持sysutils里的好多函数.

原来是没有在正确的inno事件中调用.
方法
设置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已经通知刷新系统变量了,所以不起作用.要在通知刷新之前调用,经过试验前面两个事件时机结果正确.
 

风铃夜思雨

Unregistered / Unconfirmed
GUEST, unregistred user!
我说主要是Integer(Pchar(str))这样的脚本用法pascal不支持

我重编译以实现这种方法
 
J

jsjxuwenjun

Unregistered / Unconfirmed
GUEST, unregistred user!
inno setup有的脚本不支持,所以经常偷懒:把需要的功能封在一个EXE文件里,在安装过程执行EXE,安装结束删除EXE.
 
L

LSUPER

Unregistered / Unconfirmed
GUEST, unregistred user!
inno 万能的扩展方法是把代码封装到 dll 然后 inno pascal script 中调用
 
D

dejoy

Unregistered / Unconfirmed
GUEST, unregistred user!
TO 风铃夜思雨,
我在用你的重编译版本,innosetup_5.2.3 重编译版,希望新版本能加入ISPP,我试过只要替换以下几下文件就可以了:
ISCmplr.dll
SetupLdr.e32
ISCmplr.dls
ISPP.chm
Builtins.iss
是从Inno QuickStart Pack-5.2.3中提取的,我已经做成了一个压缩包,如果你需要,我提供给你.
 

风铃夜思雨

Unregistered / Unconfirmed
GUEST, unregistred user!
我的重编译版,本就有提供有,只要你选择安装即可

分增强功能版,标准功能版。可选ISPP安装等

最新可到http://u.skygz.com/?skygz 汉化目录下下载
 
D

dejoy

Unregistered / Unconfirmed
GUEST, unregistred user!
是吗,还分两个版本,那我可能下到的是标准版,下了你的增强版,的确不一样.
 
D

dejoy

Unregistered / Unconfirmed
GUEST, unregistred user!
TO 风铃夜思雨,
你的汉化增强版非常好用,不过我发现配合Inno_Script_Generator_1.0.3.1使用时无法编译,提示Resuouce updated error...,请测试下
Inno_Script_Generator是个很好的inno script工具,和ISTOOL差不多,不过貌似更强大些,支持ISSP,只是自带的中文语言太差了,只汉化了10%,你能否做个完整汉化版本?
 
顶部