inno 程序安装脚本,检测.net framework 环境并提供.net 2.0sp2下载链接

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!


#define MyAppName "autoPing"
#define MyAppVersion "3.0"
#define MyAppPublisher "枫浪软件工作室"
#define MyAppURL "http://blog.csdn.net/fl_xin"
#define MyAppExeName "autoping.exe"
#define MyAppHelpName "autoPing帮助文档.doc"
[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{E710E9EC-59FB-4BAE-9912-2E2445AAD4CA}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
LicenseFile=许可文件.txt
;InfoBeforeFile=安装前显示.txt
InfoAfterFile=安装后显示.txt
OutputDir=G:\
OutputBaseFilename=autoPingSetup
SetupIconFile=ping.ico
WizardImageFile=logo.bmp     
WizardSmallImageFile=20150112201658.bmp
Compression=lzma
SolidCompression=yes


[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"


[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkedonce; OnlyBelowVersion: 0,6.1
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked




[Files]
Source: "autoping.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "autoping.exe.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "autoPing帮助文档.chm"; DestDir: "{app}"; Flags: ignoreversion
Source: "autoPing帮助文档.doc"; DestDir: "{app}"; Flags: isreadme
Source: "Database.apdb"; DestDir: "{app}"; Flags:  ignoreversion
Source: "演示数据3.apdb"; DestDir: "{app}"; Flags: ignoreversion
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”


[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{#MyAppHelpName}"; Filename: "{app}\{#MyAppHelpName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon


;安装结束后要运行的选项,可选
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent






[Code]


function IsDotNetDetected(version: string; service: cardinal): boolean;
// Indicates whether the specified version and service pack of the .NET Framework is installed.
//
// version -- Specify one of these strings for the required .NET Framework version:
//    'v1.1.4322'     .NET Framework 1.1
//    'v2.0.50727'    .NET Framework 2.0
//    'v3.0'          .NET Framework 3.0
//    'v3.5'          .NET Framework 3.5
//    'v4\Client'     .NET Framework 4.0 Client Profile
//    'v4\Full'       .NET Framework 4.0 Full Installation
//    'v4.5'          .NET Framework 4.5
//
// service -- Specify any non-negative integer for the required service pack level:
//    0               No service packs required
//    1, 2, etc.      Service pack 1, 2, etc. required
var
    key: string;
    install, release, serviceCount: cardinal;
    check45, success: boolean;
begin
    // .NET 4.5 installs as update to .NET 4.0 Full
    if version = 'v4.5' then begin
        version := 'v4\Full';
        check45 := true;
    end else
        check45 := false;


    // installation key group for all .NET versions
    key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + version;


    // .NET 3.0 uses value InstallSuccess in subkey Setup
    if Pos('v3.0', version) = 1 then begin
        success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install);
    end else begin
        success := RegQueryDWordValue(HKLM, key, 'Install', install);
    end;


    // .NET 4.0/4.5 uses value Servicing instead of SP
    if Pos('v4', version) = 1 then begin
        success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount);
    end else begin
        success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount);
    end;


    // .NET 4.5 uses additional value Release
    if check45 then begin
        success := success and RegQueryDWordValue(HKLM, key, 'Release', release);
        success := success and (release >= 378389);
    end;


    result := success and (install = 1) and (serviceCount >= service);
end;


var Path:string ;
    ResultCode: Integer;
    MykeynotExist:boolean;
    uicmd: String;




function InitializeSetup(): Boolean;
begin
    MykeynotExist:= true;
    if RegQueryStringValue(HKEY_LOCAL_MACHINE, 
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{E710E9EC-59FB-4BAE-9912-2E2445AAD4CA}_is1', 'UninstallString', uicmd) then
        begin
        MsgBox('安装程序检测到您的系统中已经安装相同版本autoPing,'#13'建议您备份数据文件后卸载原程序再重新运行安装程序。',mbInformation,MB_OK)
        MyKeynotExist:= false;
        Exec(RemoveQuotes(uicmd), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
        Result:= MykeynotExist
        end
    else


        begin
            if not ( IsDotNetDetected('v2.0.50727', 1)or
                    IsDotNetDetected('v2.0.50727', 2)or 
                    IsDotNetDetected('v3.0', 0)or
                    IsDotNetDetected('v3.5', 0)or
                    IsDotNetDetected('v4\Client', 0)or
                    IsDotNetDetected('v4\Full', 0)or
                    IsDotNetDetected('v4.5', 0)
                      )
            then 
                      begin


                          if  MsgBox('本软件运行需要.Net Framework2.0 sp1以上环境,系统检测到您没有安装.'#13#13
                                    '是否立刻下载并安装?'#13'', mbInformation, MB_YESNO)=idyes 
                          then 
                              begin
                              Path := ExpandConstant('{pf}\Internet Explorer\iexplore.exe');
                              Exec(Path, 'http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe', '' , SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
                              MsgBox('请安装好.Net Framework2.0环境后,再运行本安装包程序!',mbInformation,MB_OK);
                              Result := false;
                              end 
                          else 
                              begin
                              MsgBox('没有安装.Net Framework2.0 sp1以上环境,无法运行程序,本安装程序即将退出!',mbInformation,MB_OK);
                              Result := false;
                          end;
                      end 
            else
            result := true;
       end;
    end;


CODE段为Pascal语言。

你可能感兴趣的:(inno)