[转]NSIS:安装、卸载时检查程序是否正在运行

原文连接 http://www.flighty.cn/html/bushu/20110402_115.htmlhtml

 

若是咱们要安装或升级的程序正在运行,文件确定会替换失败,如下代码能够提示用户结束正在运行的程序。ui

须要使用插件FindProcDLL.dll,下载路径:http://nsis.sourceforge.net/FindProcDLL_plug-in
 spa

http://files.cnblogs.com/files/z5337/FindProc.zip.net

http://files.cnblogs.com/files/z5337/KillProcDll%26FindProcDll.zip插件

 

开始安装时检查flighty.exe是否正在运行:code

Function .onInit
  ;关闭进程
  Push $R0
  CheckProc:
    Push "flighty.exe"
    ProcessWork::existsprocess
    Pop $R0
    IntCmp $R0 0 Done
    MessageBox MB_OKCANCEL|MB_ICONSTOP "安装程序检测到 ${PRODUCT_NAME} 正在运行。$\r$\n$\r$\n点击 “肯定” 强制关闭${PRODUCT_NAME},继续安装。$\r$\n点击 “取消” 退出安装程序。" IDCANCEL Exit
    Push "flighty.exe"
    Processwork::KillProcess
    Sleep 1000
    Goto CheckProc
    Exit:
    Abort
    Done:
    Pop $R0
FunctionEnd

开始卸载时检查flighty.exe是否正在运行:htm

 

Function un.onInit
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要彻底移除 $(^Name) ,及其全部的组件?" IDYES +2
  Abort
  ;检测程序是否运行
  FindProcDLL::FindProc "flighty.exe"
   Pop $R0
   IntCmp $R0 1 0 no_run
   MessageBox MB_ICONSTOP "卸载程序检测到 ${PRODUCT_NAME} 正在运行,请关闭以后再卸载!"
   Quit
   no_run:
FunctionEnd

 

顺便提一句:若是你的程序被360误杀过,能够用这个提示用户关闭360才能够进行安装。blog

相关文章
相关标签/搜索