创建installer的实例

原创 2015年07月09日 03:37:46
# Script generated by the HM NIS Edit Script Wizard.


# HM NIS Edit Wizard helper defines
!define PRODUCT_GROUP "Fiber Mountain"
!define PRODUCT_NAME "Aos"
!define PRODUCT_VERSION "VERSIONSTRING"
!define PRODUCT_PUBLISHER "Fiber Mountain Inc."
!define PRODUCT_WEB_SITE "http://www.fibermountain.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\${PRODUCT_GROUP}\${PRODUCT_NAME}"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_GROUP}\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"


!define STARTMENUBASE "${PRODUCT_GROUP}\${PRODUCT_NAME}"




Var Desktopshortcut
Var Quicklaunchshortcut
#Var dsktopState


# MUI 1.67 compatible ------
!include "InstallOptions.nsh"
!include "MUI2.nsh"
!include "x64.nsh"


#installer attribute, remove version string
BrandingText " "


# MUI Settings ------
!define MUI_ABORTWARNING
# set logos
!define MUI_ICON "assets\logo.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
# set default section description empty
!define MUI_INNERTEXT_COMPONENTS_DESCRIPTION_INFO " "
# finish run link settings, This define value does not make any different but the define needs to be there for the page to show.
!define MUI_FINISHPAGE_RUN "Blah"


# set welcome page picture, commended size: 164x314 pixels
!define MUI_WELCOMEFINISHPAGE_BITMAP "assets\datacenter.bmp"


#Set intallment pages
# Welcome page
!insertmacro MUI_PAGE_WELCOME


# License page
#!define MUI_LICENSEPAGE_CHECKBOX
#!insertmacro MUI_PAGE_LICENSE "Install\license.rtf"


# Check whether componenets have been selected
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MustChooseComponents


# Components page
!insertmacro MUI_PAGE_COMPONENTS
# Directory page
Page Directory "" "" DirLeave


# Instfiles page
Page InstFiles


# Shortcut page, this is custom page
Page custom SetShortcut


# This is for the option to launch the application at the end of the installation.
#!define MUI_FINISHPAGE_RUN_TEXT "Add shortcut to Start Menu"
!define MUI_FINISHPAGE_RUN_FUNCTION "RunApp"
!insertmacro MUI_PAGE_FINISH


# Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES


# Language files
!insertmacro MUI_LANGUAGE "English"


# MUI end ------




!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
        messageBox mb_iconstop "Administrator rights required!"
        setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
        quit
${EndIf}
!macroend




# specify installment directory and output file name
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "OUTPUTFILE.exe"


; This line fixed the problem with removing desktop shortcuts.
; The level must be NONE for the shortcuts to be created!!!
;RequestExecutionLevel none


;when create a start menu directory for shortcuts, the executionLevel could be admin
RequestExecutionLevel admin


InstallDir "$PROGRAMFILES\${PRODUCT_GROUP}"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show




Function DirLeave
${If} ${FileExists} "$InstDir\*"
    MessageBox MB_YESNO `"$InstDir" already exists, delete it's content and continue installing?` IDYES yep
    Abort
yep:
  ${If} ${FileExists} "$PROGRAMFILES\FMBackup\*.*"
  ${Else}
    CreateDirectory "$PROGRAMFILES\FMBackup"
  ${EndIf}
  CopyFiles "$INSTDIR\${PRODUCT_NAME}\Exported Files\*.*" "$PROGRAMFILES\FMBackup"
  RMDir /r $INSTDIR
  CreateDirectory "$INSTDIR\${PRODUCT_NAME}\Exported Files"
  CopyFiles "$PROGRAMFILES\FMBackup\*.*" "$INSTDIR\${PRODUCT_NAME}\Exported Files"
  RMDir /r "$PROGRAMFILES\FMBackup"
${EndIf}
FunctionEnd


# components to be installed
Section "Jre_64 bits" INSTALLJRE64
    SectionIn RO
    SetOutPath "$INSTDIR\${PRODUCT_NAME}\JRE"
    SetOverwrite ifnewer
    File /r "Install\JREs\64Bits\windows\"
SectionEnd


Section "Core" INSTALLCORE
  SectionIn RO
  SetOutPath "$INSTDIR\${PRODUCT_NAME}" #No need to add Aos Manager, the installation already appended it
  SetOverwrite ifnewer
  File /r /x fimoServer /x dist /x Readme.txt /x Aos.exe /x Aos.jar /x Initializer.exe /x Planner.exe /x PlannerStandalone.exe /x AosStandalone.exe /x Server.exe "Install\${PRODUCT_NAME}\" "assets\logo.ico"
SectionEnd


Section "Server" INSTALLSERVER
  SetOutPath "$INSTDIR\${PRODUCT_NAME}" #No need to add Aos Manager, the installation already appended it
  SetOverwrite ifnewer
  File "Install\${PRODUCT_NAME}\Server.exe"
  ;check "run as admin" checkbox of .exe files
  WriteRegStr HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\${PRODUCT_NAME}\Server.exe" "RUNASADMIN"
SectionEnd


Section "Aos Client" INSTALLAOS
  SetOutPath "$INSTDIR\${PRODUCT_NAME}" #No need to add Aos Manager, the installation already appended it
  SetOverwrite ifnewer
  File "Install\${PRODUCT_NAME}\Aos.exe" "Install\${PRODUCT_NAME}\AosStandalone.exe"
  ;check "run as admin" checkbox of .exe files
  WriteRegStr HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\${PRODUCT_NAME}\Aos.exe" "RUNASADMIN"
  WriteRegStr HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\${PRODUCT_NAME}\AosStandalone.exe" "RUNASADMIN"
SectionEnd


;Section "Planner Client" INSTALLPLANNER
;  SetOutPath "$INSTDIR\${PRODUCT_NAME}" #No need to add Aos Manager, the installation already appended it
;  SetOverwrite ifnewer
;  File "Install\${PRODUCT_NAME}\Planner.exe" "Aos Manager\PlannerStandalone.exe"
;SectionEnd


;Section "Initializer Client" INSTALLINITIALIZER
;  SetOutPath "$INSTDIR\${PRODUCT_NAME}" #No need to add Aos Manager, the installation already appended it
;  SetOverwrite ifnewer
;  File "Install\${PRODUCT_NAME}\Initializer.exe"
;SectionEnd


#----------------------


# read in custom page setting file .ini
Function .onInit
  !insertmacro INSTALLOPTIONS_EXTRACT_AS "assets\shortcutoptions.ini" "shortcutoptions.ini"
  ;if system is 64 bit, change default directory
  ${If} ${RunningX64}
      SetRegView 64
      StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCT_GROUP}"
  ${ENDIf}
  setShellVarContext all
  !insertmacro VerifyUserIsAdmin
FunctionEnd


# configure elements on "SetShortcut" custom page
Function SetShortcut
         !insertmacro MUI_HEADER_TEXT "Additional Shortcut Options" ""
         !insertmacro INSTALLOPTIONS_DISPLAY "shortcutoptions.ini"
         !insertmacro INSTALLOPTIONS_READ $Desktopshortcut "shortcutoptions.ini" "Field 1" "State"
         !insertmacro INSTALLOPTIONS_READ $Quicklaunchshortcut "shortcutoptions.ini" "Field 2" "State"
         Call CreateShortcuts
FunctionEnd


Function MustChooseComponents
#if section is selected, $1 = 1, otherwise $1 = 0
    SectionGetFlags ${INSTALLSERVER} $1
    SectionGetFlags ${INSTALLAOS} $2
    IntOp $0 $1 || $2
    ${If} $0 == 0
        MessageBox MB_OK|MB_ICONSTOP 'Please choose at least one component to install.'
        Abort
    ${EndIf}
FunctionEnd


# when finish page is shown, trigger this function
Function CreateShortcuts
  SetShellVarContext all
  createDirectory "$SMPROGRAMS\${STARTMENUBASE}"




  ${If} ${SectionIsSelected} ${INSTALLSERVER}
         CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\Server.lnk" "$INSTDIR\${PRODUCT_NAME}\Server.exe" "" "$INSTDIR\${PRODUCT_NAME}\logo.ico"
         #recommend shortcut icon size is 48 * 48 for 32 bit colors
        ${If} $Desktopshortcut == 1
              CreateShortCut "$DESKTOP\Server.lnk" "$INSTDIR\${PRODUCT_NAME}\Server.exe" "" "$INSTDIR\${PRODUCT_NAME}\logo.ico"
        ${EndIf}
        ${If} $Quicklaunchshortcut == 1
              CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\Server.lnk" "$INSTDIR\${PRODUCT_NAME}\Server.exe" "" "$INSTDIR\${PRODUCT_NAME}\logo.ico"
        ${EndIf}
  ${EndIf}


  ${If} ${SectionIsSelected} ${INSTALLAOS}
        CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\AosClient.lnk" "$INSTDIR\${PRODUCT_NAME}\Aos.exe" "" "$INSTDIR\${PRODUCT_NAME}\logo.ico"
;        CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\AosStandalone.lnk" "$INSTDIR\${PRODUCT_NAME}\AosStandalone.exe" "" "$INSTDIR\${PRODUCT_NAME}\logo.ico"


        ${If} $Desktopshortcut == 1
              CreateShortCut "$DESKTOP\AosClient.lnk" "$INSTDIR\${PRODUCT_NAME}\Aos.exe" "" "$INSTDIR\${PRODUCT_NAME}\logo.ico"
;              CreateShortCut "$DESKTOP\AosStandalone.lnk" "$INSTDIR\${PRODUCT_NAME}\AosStandalone.exe" "" "$INSTDIR\${PRODUCT_NAME}\logo.ico"
        ${EndIf}
        ${If} $Quicklaunchshortcut == 1
              CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\AosClient.lnk" "$INSTDIR\${PRODUCT_NAME}\Aos.exe"
;              CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\AosStandalone.lnk" "$INSTDIR\${PRODUCT_NAME}\AosStandalone.exe"
        ${EndIf}
  ${EndIf}


;  ${If} ${SectionIsSelected} ${INSTALLPLANNER}
;        ${If} $Desktopshortcut == 1
;              CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\PlannerClient.lnk" "$INSTDIR\${PRODUCT_NAME}\Planner.exe"
;              CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\PlannerStandalone.lnk" "$INSTDIR\${PRODUCT_NAME}\PlannerStandalone.exe"
;        ${EndIf}
;  ${EndIf}


;  ${If} ${SectionIsSelected} ${INSTALLINITIALIZER}
;        ${If} $Desktopshortcut == 1
;              CreateShortcut "$SMPROGRAMS\${STARTMENUBASE}\Initializer.lnk" "$INSTDIR\${PRODUCT_NAME}\Initializer.exe"
;        ${EndIf}
;  ${EndIf}




FunctionEnd


Function RunApp
         ${If} ${SectionIsSelected} ${INSTALLAOS}
               ExecShell "" "$INSTDIR\${PRODUCT_NAME}\Aos.exe"
         ${EndIf}
FunctionEnd




Section -AdditionalIcons
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}\Website.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  createDirectory "$SMPROGRAMS\${STARTMENUBASE}"
  CreateShortCut "$SMPROGRAMS\${STARTMENUBASE}\Website.lnk" "$INSTDIR\${PRODUCT_NAME}\Website.url"
  CreateShortCut "$SMPROGRAMS\${STARTMENUBASE}\Uninstall.lnk" "$INSTDIR\${PRODUCT_NAME}\uninst.exe"
SectionEnd


Section -Post
  WriteUninstaller "$INSTDIR\${PRODUCT_NAME}\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\Aos.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\${PRODUCT_NAME}\uninst.exe"
;  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\${PRODUCT_NAME}\Aos.exe"aaaaaaaa
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  #WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"


  ;create registry keys for uninstaller in programs and features in control panel
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
                 "DisplayName" "${PRODUCT_NAME}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
                 "UninstallString" "$\"$INSTDIR\${PRODUCT_NAME}\uninst.exe$\""




SectionEnd


# Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${INSTALLJRE64} "Java Runtime Environment 64 bits"
  !insertmacro MUI_DESCRIPTION_TEXT ${INSTALLCORE} "${PRODUCT_NAME} core files"
  !insertmacro MUI_DESCRIPTION_TEXT ${INSTALLSERVER} "${PRODUCT_NAME} server files"
  !insertmacro MUI_DESCRIPTION_TEXT ${INSTALLAOS} "${PRODUCT_NAME} client files"
;  !insertmacro MUI_DESCRIPTION_TEXT ${INSTALLPLANNER} "${PRODUCT_NAME} planner files"
;  !insertmacro MUI_DESCRIPTION_TEXT ${INSTALLINITIALIZER} "${PRODUCT_NAME} initializer files"
!insertmacro MUI_FUNCTION_DESCRIPTION_END




Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd


Function un.onInit
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
  Abort
FunctionEnd


Section Uninstall
  SetShellVarContext all


  ;RMDir /r $INSTDIR
  ${If} ${FileExists} "$PROGRAMFILES\FMBackup\*.*"
  ${Else}
    CreateDirectory "$PROGRAMFILES\FMBackup"
  ${EndIf}
  CopyFiles "$INSTDIR\Exported Files\*.*" "$PROGRAMFILES\FMBackup"
  RMDir /r $INSTDIR
  CreateDirectory "$INSTDIR\Exported Files"
  CopyFiles "$PROGRAMFILES\FMBackup\*.*" "$INSTDIR\Exported Files"
  RMDir /r "$PROGRAMFILES\FMBackup"


  Delete "$DESKTOP\Initializer.lnk"
  Delete "$DESKTOP\PlannerClient.lnk"
  Delete "$DESKTOP\PlannerStandalone.lnk"


  Delete "$DESKTOP\AosClient.lnk"
;  Delete "$DESKTOP\AosStandalone.lnk"


  Delete "$DESKTOP\Server.lnk"
  RMDir /r "$SMPROGRAMS\${PRODUCT_GROUP}"




  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"


  ;remove registry keys for uninstaller in programs and features in control panel
  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"


  SetAutoClose true
SectionEnd

相关文章推荐

使用Universal USB Installer创建安装Linux U盘系统

使用Universal USB Installer创建安装Linux U盘系统详细步骤。

使用Advanced Installer制作IIS安装包(二:配置安装包依赖项和自定义dll)

前言:上篇使用Advanced Installer制作IIS安装包(一:配置IIS和Web.config)介绍了下使用Advanced Installer配置IIS和Web.config的过程,操作起...

不能访问Windows Installer的解决方法

安装任何软件都提示不能访问windows Installer服务之解决方法   安装软件时右手会提示:不能访问windows Installer服务,可能是你在安全模式下运行windows或者win...

.NET vs installer安装项目失败汇总

vs installer项目打包winform程序总结,并通过vbs安装mysql-connector-net-6.6.5.msi

Advance Installer安装问题

这几天需要用Advance Installer打包,在打包的过程中需要注册DLL。结果各种注册不上,最终在同事的帮助下解决了。。。万幸...
  • wasb001
  • wasb001
  • 2015年03月12日 15:46
  • 1339

解决Windows Installer 无法打开此修补程序包的问题

症状 当您首次尝试安装 Microsoft Office 程序或运行某个 Office 程序时,可能收到一条错误消息。如果您是通过 Administrator 用户帐户登录计算机的,可能收到下面的错...

How to Interpret Windows Installer Logs

If you have a problem with the Windows Installer or an MSI package you're installing, it's a sure be...
  • snlei
  • snlei
  • 2011年09月21日 16:46
  • 781

linux之universal usb installer安装ubuntu

Universal-USB-Installer这个工具是用来制作U盘启动盘的,下面以制作Ubuntu版本Linux系统的U盘启动盘为例,方法如下: 1、安装Universal USB Install...

Tips of Windows Installer

最近做安装文件,尽管msdn上有完备的Setup project的介绍,但有些tips需要牢记: 前提:建立好Setup Project 1. 添加项目的时候,可以添加为同个sln下的其它proj...

Linux下使用Update Installer升级WebSphere7的JDK

一、准备工作
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:创建installer的实例
举报原因:
原因补充:

(最多只允许输入30个字)