NSIS制作的安装包杀掉正在运行进程的方法

当我们在卸载程序或者更新安装程序时,我们需要先将运行的进程杀掉再进行安装或者卸载程序。NSIS本身并没有提供杀掉进程的脚本,但是有一个插件可以实现此功能,插件的名字叫KillProcDLL,插件下载地址为http://nsis.sourceforge.net/KillProcDLL_plug-in。插件的用法请参考插件页面所提供的内容。下面给出在安装包中的代码:



;This callback will be called when the installer is nearly finished initializing. If the '.onInit' function calls Abort, the installer will quit instantly
Function .onInit
KillProcDLL::KillProc "myprogram.exe"
FunctionEnd


;This callback is called when the user hits the 'cancel' button after the install has failed (if it could not extract a file, or the install script used the Abort command).
Function .onInstFailed
ExecShell "open" "$INSTDIRmyprogram.exe"
FunctionEnd


;This callback will be called when the uninstaller is nearly finished initializing. If the 'un.onInit' function calls Abort, the uninstaller will quit instantly. Note that this function can verify and/or modify $INSTDIR if necessary.
Function un.onInit
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to uninstall $(^Name) and its componments?" IDYES NoAbort IDYES +2
  Abort
NoAbort:
KillProcDLL::KillProc "myprogram.exe"
FunctionEnd




  • .onInit为安装程序启动时触发的事件,此处杀掉进程是防止更新安装时不能更新主程序的问题
  • .onInstFailed为安装失败时触发的事件,此处启动程序文件是为防止安装失败后本该运行着的程序因为前面被杀掉不能继续运行
  • un.onInit为初始化卸载过程时触发的事件,在此事件的对话框选Yes的时候,即确认要卸载的时候跳转到NoAbort并杀掉进程,选No的时候不做任何操作。

  本文中的方法仅供参考,在使用过程中请自行修改此脚本。


转载原文地址:http://bcoder.com/others/kill-process-when-install-or-uninstall-programs-by-the-package-made-by-nsis

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值