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 "SoftwareAppName" ""



  ;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}DocsModern UILicense.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 "SoftwareAppName" "AppName" "$INSTDIRAppName.exe"

  

  ;Create uninstaller

  WriteUninstaller "$INSTDIRUninstall.exe"

  

  CreateShortCut "$DESKTOPAppName.lnk" "$INSTDIRAppName.exe"

  CreateShortCut "$SMPROGRAMSAppName.lnk" "$INSTDIRAppName.exe"

  CreateShortCut "$SMPROGRAMSuninstall AppName.lnk" "$INSTDIRUninstall.exe"

  ;CreateShortCut "$QUICKLAUNCHAppName.lnk" "$INSTDIRAppName.exe"



SectionEnd



Section -Post

  

  WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallAppName" "DisplayIcon" "${SOURCE_DIR}/AppName.ico"

  WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallAppName" "Publisher" "3g2win"

  WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallAppName" "DisplayName" "AppName"

  WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallAppName" "DisplayVersion " "1.0.0"

  WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallAppName" "UninstallString" "$INSTDIRUninstall.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 "$INSTDIRUninstall.exe"



  RMDir /r "$INSTDIR"

  Delete "$DESKTOPAppName.lnk"

  Delete "$SMPROGRAMSAppName.lnk"

  Delete "$SMPROGRAMSuninstall AppName.lnk"

  

  DeleteRegKey /ifempty HKCU "SoftwareAppNameAppName"

  DeleteRegKey HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallAppName"

  ;SetAutoClose true

SectionEnd

AppExample.nsi.rar http://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

原文地址:https://www.cnblogs.com/grj1046/p/3566516.html