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語言。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章