nisi 脚本示例

只是简单的copy文件和添加快捷方式,安装和卸载时对程序是否运行进行检测


;--------------------------------

;Include Modern UI

  !include "MUI2.nsh"

;--------------------------------

;Interface Settings

  !define MUI_ABORTWARNING

  !define PRODUCT_UNINST_KEY "Software/Microsoft/Windwos/CurrentVersion/Uninstall/AppName"

  !define SOURCE_DIR "G:/emulator"
  
;--------------------------------

;General

  ;Name and file

  Name "AppName"

  OutFile "AppNameSetup.exe"

  ;Default installation folder

  InstallDir "C:\AppName"

  Icon "${SOURCE_DIR}/App.ico"

  ;UninstallIcon "App.ico"

  UninstallCaption "uninstall AppName"

  ;Get installation folder from registry if available

  InstallDirRegKey HKCU "Software\AppName" ""



  ;Request application privileges for Windows Vista

  RequestExecutionLevel admin


;--------------------------------

;Pages

  !define MUI_ICON "${SOURCE_DIR}/App.ico"

  !define MUI_UNICON "${SOURCE_DIR}/App.ico"



  ;!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"

  ;!insertmacro MUI_PAGE_COMPONENTS

  !insertmacro MUI_PAGE_DIRECTORY

  !insertmacro MUI_PAGE_INSTFILES

  

  !insertmacro MUI_UNPAGE_WELCOME

  !insertmacro MUI_UNPAGE_CONFIRM

  !insertmacro MUI_UNPAGE_INSTFILES

  !insertmacro MUI_UNPAGE_FINISH

  
;--------------------------------

;Languages

 
  !insertmacro MUI_LANGUAGE "SimpChinese"

;--------------------------------

;Installer Sections

Function .onInit

  ;检测程序是否运行

  FindProcDLL::FindProc "AppName.exe"

   Pop $R0

   IntCmp $R0 1 0 no_run

   MessageBox MB_ICONSTOP "安装程序检测到 AppName 正在运行,请关闭之后再进行安装!"

   Quit

   no_run:

FunctionEnd


Section ""

  SetOutPath "$INSTDIR"
  
  ;ADD YOUR OWN FILES HERE...

  File /r "*"

  Delete "AppName.nsi"

  Delete "AppSetup.exe"

  

  ;Store installation folder

  WriteRegStr HKCU "Software\AppName" "AppName" "$INSTDIR\AppName.exe"

  

  ;Create uninstaller

  WriteUninstaller "$INSTDIR\Uninstall.exe"

  

  CreateShortCut "$DESKTOP\AppName.lnk" "$INSTDIR\AppName.exe"

  CreateShortCut "$SMPROGRAMS\AppName.lnk" "$INSTDIR\AppName.exe"

  CreateShortCut "$SMPROGRAMS\uninstall AppName.lnk" "$INSTDIR\Uninstall.exe"

  ;CreateShortCut "$QUICKLAUNCH\AppName.lnk" "$INSTDIR\AppName.exe"



SectionEnd



Section -Post

  

  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AppName" "DisplayIcon" "${SOURCE_DIR}/AppName.ico"

  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AppName" "Publisher" "3g2win"

  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AppName" "DisplayName" "AppName"

  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AppName" "DisplayVersion " "1.0.0"

  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AppName" "UninstallString" "$INSTDIR\Uninstall.exe"


SectionEnd


;--------------------------------

;Uninstaller Section


Function un.onInit

  ;检测程序是否运行

  FindProcDLL::FindProc "AppName.exe"

   Pop $R0

   IntCmp $R0 1 0 no_run

   MessageBox MB_ICONSTOP "卸载程序检测到 AppName正在运行,请关闭之后再卸载!"

   Quit

   no_run:

FunctionEnd



Section "Uninstall"

  ;ADD YOUR OWN FILES HERE...

  Delete "$INSTDIR\Uninstall.exe"



  RMDir /r "$INSTDIR"

  Delete "$DESKTOP\AppName.lnk"

  Delete "$SMPROGRAMS\AppName.lnk"

  Delete "$SMPROGRAMS\uninstall AppName.lnk"

  

  DeleteRegKey /ifempty HKCU "Software\AppName\AppName"

  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AppName"

  ;SetAutoClose true

SectionEnd

AppExample.nsi.rar https://files.cnblogs.com/grj1046/AppExample.nsi.rar

参考

NSIS:安装、卸载时检查程序是否正在运行 http://www.flighty.cn/html/bushu/20110402_115.html

NSIS 安装脚本(备忘)http://www.cnblogs.com/meteortent/archive/2013/06/10/3130770.html

[已解决] 卸载时注册表键无法删除,很奇怪 http://www.dreams8.com/thread-12800-1-1.html

posted @ 2014-02-25 13:29  nil  阅读(900)  评论(0编辑  收藏  举报