论坛风格切换切换到宽版
  • 4315阅读
  • 5回复

【求助】INNO关于注册表文件的几个问题 [复制链接]

上一主题 下一主题
离线winr
 
发帖
78
金钱
0
威望
0
只看楼主 倒序阅读 0 发表于: 2004-12-16
我要实现这样一个功能,安装一个软件的时候,会对注册表写入一些信息,包括文件的路径,等等。这个很简单,用[Registry]可以写好。

我在[Tasks]中写了一个
Name: outreg; Description: 导出注册表文件; Flags: unchecked

然后在[Code]中写上
procedure InitializeWizard();
var iResultCode: Integer;
appDir, regFileName, keyName: String;
begin
appDir:=ExpandConstant('{pf}\green');
regFileName:= appDir+'\winr.reg';
keyName:= 'HKEY_LOCAL_MACHINE\SOFTWARE\color\green\1.0';
CreateDir(appDir);
InstExec('regedit','/E "'+regFileName+'" "'+keyName+'"', '', true, false, 0, iResultCode);
end;

这个代码是借用老虎兄提供的,目的是导入注册信息为注册表文件。

现在我的问题是:
1.注册表文件导出是在{pf}\green文件夹下面,而未必是在{app}文件夹下面。我希望得到的是在{app}文件夹下面。因为{app}不一定等于{pf}\green,用户一旦修改安装目录,注册信息就在另外地方生成了,这样不太好。

2.我要导出的注册信息,有很多内容是在[Registry]中导入的,我希望得到的是新的信息,(因为有些信息是由安装过程决定的)。实际上,我得到的是安装前的信息。PS:我是把[Code]段放在ISS文件末尾的。不晓得为什么安装文件先执行[Code]段。

3.我前面设置了[Tasks],我希望选中outreg的情况下执行[Code],不选中outreg的情况下跳过这个,不知道怎么设置。


求助达人
离线秋枫

发帖
241
金钱
180
威望
18
只看该作者 1 发表于: 2004-12-16
因为是在InitialieWizard事件中,所以它是首先执行的。

你可以在出现“安装完成”这个对话框时执行你的操作:

// 以下代码用于 Inno Setup 5.x
// 在inno Setup 4.x中可能需要改一下
procedure CurPageChanged(CurPageID: Integer);
var i: LongInt;
begin
if (CurPageID = wpFinished) then
begin
  {此处是你的操作}
end;
end;
离线秋枫

发帖
241
金钱
180
威望
18
只看该作者 2 发表于: 2004-12-16
对于Task的设定,可以在程序中用If语句判定:

举个例子:

begin
if IsTaskSelected('outreg') then
  begin
    {此处是你的操作}
  end;
end;

上述代码用于Inno Setup 5中。

在Inno Setup 4中可以对函数
function WizardSelectedTasks(const Descriptions: Boolean): String;
的返回串分析,判定用户有没有选中outreg
离线Snoopy

发帖
2128
金钱
10
威望
1
只看该作者 3 发表于: 2004-12-16
用的着这么麻烦吗?

[registry]段

Root: HKCU; Subkey: software; ValueType: string; ValueName: XX; ValueData: {src}
看到帖子标题,偶万里迢迢、赤身裸体、挥刀自宫、头扎红布、跪碎玻璃、磕头到出血、胸口碎大石、喉头顶钢枪、无视艰难险阻、全身插刀抽搐、求助喝氰化钾、看央视笑傲江湖、欣赏脑白金广告、十里长街卖身跪地、倒立 3600 度后空翻、肩抗 150 公斤杠铃、专程赶过来支持一下子!
图像加密帖
离线winr
发帖
78
金钱
0
威望
0
只看该作者 4 发表于: 2004-12-17
谢谢楼上两位。

特意找了5.0BETA来测试。还有点问题继续请教


1.InstExec段代码在5.0编译出错,在4.27上可以通过。
2.TaskSelected代码在4.*版本不支持。
“在Inno Setup 4中可以对函数
function WizardSelectedTasks(const Descriptions: Boolean): String;
的返回串分析,判定用户有没有选中outreg ”这段代码怎么写啊?



3.appDir:=ExpandConstant('{pf}\green');这段必须要和DefaultDirName一致,否则导出不了注册表文件,而如果一致,那就未必到{src} 文件夹下面了。
离线秋枫

发帖
241
金钱
180
威望
18
只看该作者 5 发表于: 2004-12-17
QUOTE(winr @ 2004年12月17日 13时17分)
谢谢楼上两位。

特意找了5.0BETA来测试。还有点问题继续请教


1.InstExec段代码在5.0编译出错,在4.27上可以通过。
2.TaskSelected代码在4.*版本不支持。
“在Inno Setup 4中可以对函数
function WizardSelectedTasks(const Descriptions: Boolean): String;
的返回串分析,判定用户有没有选中outreg ”这段代码怎么写啊?



3.appDir:=ExpandConstant('{pf}\green');这段必须要和DefaultDirName一致,否则导出不了注册表文件,而如果一致,那就未必到{src} 文件夹下面了。

InstExec函数在5中已取消,由Exec函数取代。

Prototype:

function Exec(const Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ResultCode: Integer): Boolean;

Description:
Executes the specified executable or batch file. The Wait parameter specifies whether the function should return immediately or wait until the launched process has termimated or is idle. Returns True if the specified file was executed successfully, False otherwise. If True is returned and Wait is ewWaitUntilTerminated then ResultCode returns the exit code of the process. If False is returned then ResultCode specifies the error that occurred. Use SysErrorMessage(ResultCode) to get a description of the error.

Remarks:
TExecWait is defined as:
TExecWait = (ewNoWait, ewWaitUntilTerminated, ewWaitUntilIdle);
Use the ShellExec function instead if you need to launch a non-executable/batch file.
Example:
var
ResultCode: Integer;
begin
// Launch Notepad and wait for it to terminate
if Exec(ExpandConstant('{win}\notepad.exe'), '', '', SW_SHOW,
  ewWaitUntilTerminated, ResultCode) then
begin
  // handle success if necessary; ResultCode contains the exit code
end
else begin
  // handle failure if necessary; ResultCode contains the error code
end;
end;

CODE
Innosetup 4中的WizardSelectedTasks用法:

if pos(',OUTREG,',UpperCase(','+WizardSelectedTasks(false)+','))<>0 then
 begin
   {选中了}
 end
else
 begin
   {没选中}
 end;