11 12
发新话题
打印

Inno Setup 脚本实例——选择安装:当前用户、所有用户 (更新:加了几行注释)

本主题由 马甲1号 于 2007-12-18 18:35 加入精华

Inno Setup 脚本实例——选择安装:当前用户、所有用户 (更新:加了几行注释)

加了几行注释~
复制内容到剪贴板
代码:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

; 使用预定义变量,便于维护
#define MyAppName "My Program"
#define MyAppVerName "My Program 1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"

[Setup]
AppName={#MyAppName}
AppVerName={#MyAppVerName}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
LicenseFile=D:\Program Files\Inno Setup 5\license.txt
OutputBaseFilename=setup
Compression=lzma
SolidCompression=true

[Languages]
Name: english; MessagesFile: compilerefault.isl

[CustomMessages]
; 使用自定义信息,便于维护或多国语言
cmSelectUser=Install for:
cmAllUsers=&All users
cmCurrentUserOnly=Current &user only

[Tasks]
Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}
Name: quicklaunchicon; Description: {cm:CreateQuickLaunchIcon}; GroupDescription: {cm:AdditionalIcons}
; 把“选择安装给谁”选项作为附加任务来处理
; 脚本函数 ShowSelectUserTask 用于判断是否需要显示“选择安装”选项,比如 98 下不显示该选择,细节参见相应脚本函数
Name: forallusers; Description: {cm:cmAllUsers}; GroupDescription: {cm:cmSelectUser}; Flags: exclusive; Check: ShowSelectUserTask
Name: forcurrentuser; Description: {cm:cmCurrentUserOnly}; GroupDescription: {cm:cmSelectUser}; Flags: exclusive unchecked; Check: ShowSelectUserTask

[Files]
Source: D:\Program Files\Inno Setup 5\Examples\MyProg.exe; DestDir: {app}; Flags: ignoreversion
Source: D:\Program Files\Inno Setup 5\license.txt; DestDir: {app}; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Dirs]
; “选择安装给谁”选项的应用示例,脚本函数 CheckInstallFor 用于判断是选择了 安装给所有用户 还是 安装给当前用户,由此决定安装目标目录是 所有用户 还是 当前用户
Name: {commonappdata}\{#MyAppName}\Data; Check: CheckInstallFor('forallusers')
Name: {userappdata}\{#MyAppName}\Data; Check: CheckInstallFor('forcurrentuser')

[Icons]
Name: {group}\{#MyAppName}; Filename: {app}\{#MyAppExeName}
Name: {group}\{cm:UninstallProgram,{#MyAppName}}; Filename: {uninstallexe}
; “选择安装给谁”选项的应用示例,请参考[Dirs]示例注释
Name: {commondesktop}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: desktopicon; Check: CheckInstallFor('forallusers')
Name: {userdesktop}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: desktopicon; Check: CheckInstallFor('forcurrentuser')
; 注意,我在测试过程中,发现{commonappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}不起作用,因此快速启动快捷键只安装给当前用户
Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: quicklaunchicon

[Registry]
; “选择安装给谁”选项的应用示例,请参考[Dirs]示例注释
; 这两行是卸载时候删除相应注册表内容
Root: HKLM; Subkey: Software\{#MyAppName}; Flags: uninsdeletekey dontcreatekey; ValueType: none; Check: CheckInstallFor('forallusers')
Root: HKCU; Subkey: Software\{#MyAppName}; Flags: uninsdeletekey dontcreatekey; ValueType: none; Check: CheckInstallFor('forcurrentuser')
; 这两行是安装时候在注册表内留下相应键值,来标识安装过程中的“选择安装”选项
Root: HKLM; Subkey: Software\{#MyAppName}; ValueType: string; ValueName: InstallFlag; ValueData: ForAllUser; Check: CheckInstallFor('forallusers')
Root: HKCU; Subkey: Software\{#MyAppName}; ValueType: string; ValueName: InstallFlag; ValueData: ForCurrentUser; Check: CheckInstallFor('forcurrentuser')

[UninstallDelete]
Name: {app}\MyProg.exe; Type: files
Name: {app}\license.txt; Type: files
Name: {app}; Type: dirifempty
; “选择安装给谁”选项的应用示例,请参考[Dirs]示例注释
Name: {commonappdata}\{#MyAppName}\Data; Type: dirifempty; Check: CheckInstallFor('forallusers')
Name: {userappdata}\{#MyAppName}\Data; Type: dirifempty; Check: CheckInstallFor('forcurrentuser')

[Run]
Filename: {app}\{#MyAppExeName}; Description: {cmaunchProgram,{#MyAppName}}; Flags: nowait postinstall skipifsilent

[Code]

// 是否显示“选择安装给谁”选项,这里我认为显示的条件是:NT 平台,且为 Amdin 用户
function ShowSelectUserTask: Boolean;
begin
  Result := UsingWinNT and IsAdminLoggedOn;
end;

// 判断“选择安装给谁”选项值
function CheckInstallFor(Task: string): Boolean;
begin
  if UsingWinNT then
  begin
    Result := IsTaskSelected(Task);
    if Result and (Task = 'forallusers') then
      Result := ShowSelectUserTask;
  end
  else
    Result := Task = 'forallusers';
end;

// 安装向导页面改变事件
procedure CurPageChanged(CurPageID: Integer);
var
  I: Integer;
  WinVer: TWindowsVersion;
begin
  if (CurPageID = wpSelectTasks) then
  begin // 当前页为 附加任务 选择页
    GetWindowsVersionEx(WinVer);
    if UsingWinNT and (not IsAdminLoggedOn or (WinVer.Major > 5)) then
    begin // NT 平台,且 不是 Admin 用户 或 是 Vista 系统
      for I := 0 to WizardForm.TasksList.Items.Count - 1 do
      begin
        if WizardForm.TasksList.ItemCaption = ExpandConstant('{cm:cmCurrentUserOnly}') then
          WizardForm.TasksList.Checked := True; // 默认选择为 安装给当前用户
      end;
    end;
  end;
end;

// 安装步骤改变事件
procedure CurStepChanged(CurStep: TSetupStep);
var
  S: string;
  ResultCode: Integer;
begin
  if CurStep = ssInstall then
  begin // 安装将要开始执行
    // 这里可以根据自己需要,执行特定代码。我这里只是显示一下选项值
    if IsTaskSelected('forallusers') then
      MsgBox(ExpandConstant('{cm:cmSelectUser}') + ' ' + ExpandConstant('{cm:cmCurrentUserOnly}'), mbInformation, MB_OK)
    else
      MsgBox(ExpandConstant('{cm:cmSelectUser}') + ' ' + ExpandConstant('{cm:cmAllUsers}'), mbInformation, MB_OK);
  end;
end;
[ 本帖最后由 CodeCoolie 于 2007-12-18 13:39 编辑 ]
本帖最近评分记录
  • 不可胜 活力 +5 2008-9-26 12:09
  • asalei2 活力 +5 感谢分享! 2008-3-31 14:05
  • winsoft 活力 +5 谢谢 2007-12-18 12:24
  • spng 活力 +5 感谢分享 2007-12-18 11:01
超级简单易用的音视频转换控件 2008.09.28 最新版本 2.2 推出,更强大 FFmpeg for Delphi http://www.CCAVC.com
MSN: CodeCoolie#live.com QQ: 25758206 (请填写相关验证信息, 谢谢)
成功上传头像的秘籍

TOP

谢谢分享
走别人的路,让别人无路可走

TOP

引用:
原帖由 pkill 于 2007-12-18 10:22 发表
谢谢分享
看得有点头晕,不过先收藏!

TOP

引用:
原帖由 Richfu 于 2007-12-18 10:23 发表


看得有点头晕,不过先收藏!
懒得写注释
超级简单易用的音视频转换控件 2008.09.28 最新版本 2.2 推出,更强大 FFmpeg for Delphi http://www.CCAVC.com
MSN: CodeCoolie#live.com QQ: 25758206 (请填写相关验证信息, 谢谢)
成功上传头像的秘籍

TOP

感谢分享
闭关修炼中......

TOP

谢谢分享

TOP

原来还可以写[code],一直以为就只是个INI形式的文件
坚持不发精华帖

TOP

引用:
原帖由 leny 于 2007-12-18 15:22 发表
原来还可以写,一直以为就只是个INI形式的文件
如果做普普通通的安装程序,用不上[Code]段,如果有特殊要求,[Code]段可以干 N 多事情滴。。。

The Pascal scripting feature (modern Delphi-like Pascal) adds lots of new possibilities to customize your Setup or Uninstall at run-time. Some examples:
  • Support for aborting Setup or Uninstall startup under custom conditions.
  • Support for adding custom wizard pages to Setup at run-time.
  • Support for extracting and calling DLL or other files from the Pascal script before, during or after the installation.
  • Support for scripted constants that can do anything the normal constants, the read-from-registry, read-from-ini and read-from-commandline constants can do + more.
  • Support for run-time removal of types, components and/or tasks under custom conditions.
  • Support for conditional installation of [Files], [Registry], [Run] etc. entries based on custom conditions.
  • Lots of support functions to do from the Pascal script just about everything Inno Setup itself does/can do + more.
An integrated run-time debugger to debug your custom Pascal script is also available.
The scripting engine used by Inno Setup is RemObjects Pascal Script by Carlo Kok. Like Inno Setup, RemObjects Pascal Script is freely available and comes with source. See http://www.remobjects.com/?ps for more information.
超级简单易用的音视频转换控件 2008.09.28 最新版本 2.2 推出,更强大 FFmpeg for Delphi http://www.CCAVC.com
MSN: CodeCoolie#live.com QQ: 25758206 (请填写相关验证信息, 谢谢)
成功上传头像的秘籍

TOP

谢谢分享!

TOP

多谢

TOP

 11 12
发新话题