首页 > 其他 > 详细

nisi 脚本示例

时间:2014-02-25 23:17:32      阅读:666      评论:0      收藏:0      [点我收藏+]

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

```nsi

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

;Include Modern UI

!include "MUI2.nsh"

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

;Interface Settings

!define MUI_ABORTWARNING

!define PRODUCTUNINSTKEY "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 MUIICON "${SOURCEDIR}/App.ico"

!define MUIUNICON "${SOURCEDIR}/App.ico"

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

;!insertmacro MUIPAGECOMPONENTS

!insertmacro MUIPAGEDIRECTORY

!insertmacro MUIPAGEINSTFILES

!insertmacro MUIUNPAGEWELCOME

!insertmacro MUIUNPAGECONFIRM

!insertmacro MUIUNPAGEINSTFILES

!insertmacro MUIUNPAGEFINISH

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

;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 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

nisi 脚本示例

原文:http://www.cnblogs.com/grj1046/p/3566516.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!