转载:http://www.javashuo.com/article/p-qfkfpeof-y.htmlhtml
转载:https://www.gongzi.org/nsisbuildqqstop.htmlui
转载:http://blog.sina.com.cn/s/blog_6aeaee7e0100smrn.html(若是当前程序正在运行,杀掉进程继续安装或者卸载,给了启发)spa
转载:https://blog.csdn.net/llmys/article/details/88618177(教程).net
使用场景:插件
若是咱们要安装或升级程序时,软件正在运行,这个时候安装文件确定会替换失败,友好的操做是提示用户结束正在运行的程序3d
准备工做:code
1. 检测程序是否在运行,须要使用插件FindProcDLL.dll,杀死当前运行的进程,须要使用插件KillProcDLL.dllhtm
2.这两个插件的下载地址:http://nsis.sourceforge.net/FindProcDLL_plug-in
blog
3. 放到C:\Program Files (x86)\NSIS\Plugins里面教程
4. 添加脚本
; ------ 安装前检查程序是否正在运行 Function .onInit FindProcDLL::FindProc "AppSetup.exe" Pop $R0 IntCmp $R0 1 0 no_run MessageBox MB_OKCANCEL|MB_ICONSTOP "安装程序检测到 ${PRODUCT_NAME} 正在运行。$\r$\n$\r$\n点击 “肯定” 强制关闭${PRODUCT_NAME},继续安装。$\r$\n点击 “取消” 退出安装程序。" IDCANCEL Exit KillProcDLL::KillProc "AppSetup.exe" Sleep 1000 FindProcDLL::FindProc "AppSetup.exe" Pop $R0 IntCmp $R0 1 0 no_run Exit: Quit no_run: FunctionEnd
; ------ 卸载前检查程序是否正在运行 Function un.onInit MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要彻底移除${PRODUCT_NAME},及其全部的组件?" IDYES +2 Abort ;检测程序是否运行 FindProcDLL::FindProc "AppSetup.exe" Pop $R0 IntCmp $R0 1 0 no_run KillProcDLL::KillProc "AppSetup.exe" Sleep 1000 FindProcDLL::FindProc "AppSetup.exe" Pop $R0 IntCmp $R0 1 0 no_run Quit no_run: FunctionEnd