只是简单的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 SectionsFunction .onInit ;检测程序是否运行 FindProcDLL::FindProc "AppName.exe" Pop $R0 IntCmp $R0 1 0 no_run MessageBox MB_ICONSTOP "安装程序检测到 AppName 正在运行,请关闭之后再进行安装!" Quit no_run:FunctionEndSection "" 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"SectionEndSection -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 SectionFunction un.onInit ;检测程序是否运行 FindProcDLL::FindProc "AppName.exe" Pop $R0 IntCmp $R0 1 0 no_run MessageBox MB_ICONSTOP "卸载程序检测到 AppName正在运行,请关闭之后再卸载!" Quit no_run:FunctionEndSection "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 trueSectionEnd
AppExample.nsi.rar
参考
NSIS:安装、卸载时检查程序是否正在运行
NSIS 安装脚本(备忘)
[已解决] 卸载时注册表键无法删除,很奇怪