创建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

别再耍流氓了: 请别再用strcpy, 而用strncpy 或stpcpy, strlcpy (linux)

strcpy,strncpy ,stpcpy
  • Fybon
  • Fybon
  • 2016年11月03日 16:18
  • 1294

strcpy和memcpy的区别

void *memcpy(void *dest, const void *src, int n); 从源src所指的内存地址的起始位置开始拷贝n个字节到目标dest所指的内存地址的起始位置中 #inc...
  • u014082714
  • u014082714
  • 2015年03月14日 11:59
  • 3266

【C语言】模拟实现strcpy、strcat、strcmp函数

strcpy、strcat、strcmp这三个库函数是初级学习阶段经常写到的三个库函数,也是一些大公司比较喜欢出的面试题。今天,就尝试用my_strcpy、my_strcat、my_strcmp这三个...
  • Monster_Girl
  • Monster_Girl
  • 2016年07月31日 19:06
  • 2249

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

使用Universal USB Installer创建安装Linux U盘系统详细步骤。
  • gongxifacai_believe
  • gongxifacai_believe
  • 2016年09月07日 20:51
  • 665

不能访问Windows Installer的解决方法

安装任何软件都提示不能访问windows Installer服务之解决方法   安装软件时右手会提示:不能访问windows Installer服务,可能是你在安全模式下运行windows或者win...
  • playkid123
  • playkid123
  • 2015年03月23日 11:51
  • 1401

使用LabVIEW如何生成应用程序(exe)和安装程序(installer)

 问题: 在Windows平台下使用LabVIEW如何生成一个独立可执行程序和安装程序? 解答: 为什么要生成exe和installer 使用LabVIEW编写程序的最后往往...
  • alec1987
  • alec1987
  • 2015年07月04日 16:54
  • 1456

Advanced Installer 9.4制作msi(在开始菜单添加文件夹和卸载选项)

参考链接:http://blog.csdn.net/zhangli865621030/article/details/25873729第一步:新建项目按照安装向导的提示,选择对应的保存路径等。大多选默...
  • grllery
  • grllery
  • 2017年07月22日 12:55
  • 478

如何解决无法访问Windows installer 服务

1.首先检查当前用户有没有管理员权限,因为很多时候低权限用户是不能进行软件安装的。 2.接下来,从“控制面板-服务”(或者,开始-运行-Services.msc)中察看WindowsInstal...
  • xujiangang_mmi
  • xujiangang_mmi
  • 2014年03月14日 14:06
  • 623

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

vs installer项目打包winform程序总结,并通过vbs安装mysql-connector-net-6.6.5.msi
  • shineych
  • shineych
  • 2014年08月29日 17:42
  • 1131

Visual Studio Installer文件系统(File system)安装条件(Condition)出错以及解决办法

笔者最近在Visual Studio 2010中使用Visual Studio Installer创建安装项目时碰到了一个非常奇怪的问题。 笔者想做一个installer,需要往一个已经安装过的软件...
  • yexiaozi_007
  • yexiaozi_007
  • 2013年01月24日 11:17
  • 2318
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:创建installer的实例
举报原因:
原因补充:

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