日期:2014-05-20 浏览次数:21340 次
[code]function InitializeSetup: Boolean;
var Path:string ;
     ResultCode: Integer;
     dotNetV4RegPath:string;
     dotNetV4DownUrl:string;
     dotNetV4PackFile:string;
     wic:string;
begin
dotNetV4RegPath:='SOFTWARE\Microsoft\.NETFramework\policy\v4.0';
dotNetV4DownUrl:='http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe';
dotNetV4PackFile:='{src}\update\dotNetFx40_Full_x86_x64.exe';
wic:='{src}\update\wic_x86_chs.exe';
   if RegKeyExists(HKLM, dotNetV4RegPath) then
   begin
     Result := true;
   end
   else
   begin
     Exec(ExpandConstant(wic), '/q /norestart', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
     if MsgBox('系统检测到您没有安装.Net Framework4.0运行环境,是否立即安装?', mbConfirmation, MB_YESNO) = idYes then
     begin
       Path := ExpandConstant(dotNetV4PackFile);
       if(FileOrDirExists(Path)) then
       begin
         Exec(Path, '/q /norestart', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
         if RegKeyExists(HKLM, dotNetV4RegPath) then
         begin
            Result := true;
         end
         else
         begin
            MsgBox('未能成功安装.Net Framework4.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
         end
       end
       else
       begin
         if MsgBox('软件安装目录中没有包含.Net Framework的安装程序,是否立即下载后安装?', mbConfirmation, MB_YESNO) = idYes then
         begin
           Path := ExpandConstant('{pf}\Internet Explorer\iexplore.exe');
           Exec(Path, dotNetV4DownUrl , '', 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 Framework4.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
       Result := false;
     end;
   end;
end;