标签:
InnoSetup可在在脚本中插入[Code]代码段,其中的代码可以通过事件驱动,支持的主要事件如下:
function InitializeSetup(): Boolean; ——安装程序初始化,返回值决定安装程序是否继续执行。
function NextButtonClick(CurPageID: Integer): Boolean; ——点击下一步按钮,返回值决定安装程序是否继续执行。
function BackButtonClick(CurPageID: Integer): Boolean; ——点击上一步按钮,返回值决定安装程序是否继续执行。
function InitializeUninstall(): Boolean; ——卸载程序初始化,返回值决定卸载程序是否继续执行。
...
从这些事件我们可以看到InitializeSetup()满足我们的要求,我们可以在这个时候去检查注册表或者是系统文件来判断客户机器上是否安装了.Net Framework,从而进行自动安装或者下载安装的操作。
[Code]
function InitializeSetup: Boolean;
var
Path,tmppath:string ;
ResultCode: Integer;
dotNetV2RegPath:string;
dotNetV2DownUrl:string;
dotNetV2PackFile:string;
begin
dotNetV2RegPath:=‘SOFTWARE\Microsoft\.NETFramework\Policy\v4.0‘;
dotNetV2DownUrl:=‘http://dl1sw.baidu.com/soft/9b/15910/Microsoft.NET.exe?version=585709662‘;
dotNetV2PackFile:=‘{src}\dotNetFx40_Full_x86_x64.exe‘;
//先在注册表查找.net4.0是否存在
if RegKeyExists(HKLM, dotNetV2RegPath) then
begin
Result := true;
end
//如果注册表里面没有发现.net4.0
else
begin
if MsgBox(‘系统检测到您没有安装.Net Framework4.0运行环境,是否立即安装?‘, mbConfirmation, MB_YESNO) = idYes then
begin
//和setup同级目录下的donet安装包
Path := ExpandConstant(dotNetV2PackFile);
//先抽取到临时目录
tmppath := ExpandConstant(‘{tmp}\dotNetFx40_Full_x86_x64.exe‘);
ExtractTemporaryFile(‘dotNetFx40_Full_x86_x64.exe‘);
msgbox(tmppath, mbConfirmation, MB_YESNO);
Exec(tmppath, ‘‘, ‘‘, SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
if(FileOrDirExists(tmppath)) then
begin
Exec(tmppath, ‘/q‘, ‘‘, SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
if RegKeyExists(HKLM, dotNetV2RegPath) then
begin
Result := true;
end
else
begin
MsgBox(‘未能成功安装.Net Framework4.0运行环境,系统将无法运行,本安装程序即将退出!‘,mbInformation,MB_OK);
end
end
else
begin
if MsgBox(‘软件安装目录中没有包含.Net Framework4.0的安装程序,是否立即下载后安装?‘, mbConfirmation, MB_YESNO) = idYes then
begin
Path := ExpandConstant(‘{pf}/Internet Explorer/iexplore.exe‘);
Exec(Path, dotNetV2DownUrl , ‘‘, SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
MsgBox(‘请安装好.Net Framework4.0环境后,再运行本安装包程序!‘,mbInformation,MB_OK);
Result := false;
end
else
begin
MsgBox(‘不下载安装.Net Framework4.0运行环境,系统将无法运行,本安装程序即将退出!‘,mbInformation,MB_OK);
Result := false;
end
end
end
else
begin
MsgBox(‘没有安装.Net Framework2.0运行环境,系统将无法运行,本安装程序即将退出!‘,mbInformation,MB_OK);
Result := false;
end;
end;
end;
参考链接1:http://blog.csdn.net/hualei/article/details/2628312
参考链接2:http://zhoufoxcn.blog.51cto.com/792419/279243/
InnoSetup自动检测并安装.Net Framework
标签:
原文地址:http://www.cnblogs.com/lovelp/p/4437839.html