inno setup实现.net环境检测、开机启动、桌面快捷方式的示例

1.支持xp系统运行的innosetup版本为5.x.x,下载地址http://files.jrsoftware.org/is/5/

2.脚本代码如下:

; Demonstrates copying 3 files and creating an icon.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING .ISS SCRIPT FILES!

#define MyAppName "MyProgram"
#define MyAppVersion "3.1.0"
#define MyAppPublisher "****科技有限公司"
#define MyAppURL "http://www.*****.com/"
#define MyAppExeName "MyProgram.exe"

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (若要生成新的 GUID,可在菜单中点击 "工具|生成 GUID"。)
AppId={{7F5BBF43-69D6-4E5A-8702-1DDEAEC5B7E6}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
UsePreviousAppDir=no
DefaultDirName=D:\{pf}\{#MyAppName}
DefaultGroupName=MyProgram
AllowNoIcons=yes
; 以下行取消注释,以在非管理安装模式下运行(仅为当前用户安装)。
;PrivilegesRequired=lowest
OutputDir=D:\myWork\安装包
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
WizardStyle=modern

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

[Tasks]
Name: "desktopicon"; Description: "桌面快捷方式"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "startupicon"; Description: "开机启动"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "D:\myWork\app\MyProgram.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\myWork\app\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "D:\myWork\dotnetfx35.exe"; DestDir: "{tmp}"; Flags: ignoreversion

[code] 
function InitializeSetup(): Boolean;   
var sVersion: Cardinal;
    ResultCode: Integer;
begin
      if RegKeyExists(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5') then
            begin
                  if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5','Install',sVersion) then
                     if sVersion=1 then
                         begin
                             MsgBox('你的电脑安装了.net3.5', mbInformation,MB_OK); 
                             Result := true;
                         end
                     else
                         begin
                              MsgBox('你的电脑没有安装.net3.5,将开始安装。。', mbError,MB_OK);
                              ExtractTemporaryFile('dotnetfx35.exe'); 
                              Exec(ExpandConstant('{tmp}\dotnetfx35.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode); 
                              Result := true;
                         end
            end
       else
            begin
                 MsgBox('未读取到值,你的电脑没有安装.net3.5,将开始安装', mbInformation,MB_OK); 
                 ExtractTemporaryFile('dotnetfx35.exe');
                 Exec(ExpandConstant('{tmp}\dotnetfx35.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
                 Result := true;
            end
end;
  
[Icons]
Name: "{userdesktop}\{#MyAppName}";Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}";Tasks: desktopicon
Name: "{commonstartup}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: startupicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

3.在[Files]下添加相应的文件资源,即可使用

注:本文只做了.net3.5的检测,其他版本类似处理即可

你可能感兴趣的:(inno setup实现.net环境检测、开机启动、桌面快捷方式的示例)