NSIS 安装、卸载程序时检测程序是否在运行,给出解决选择

3 篇文章 0 订阅

首先,FindProcDLL这个dll已经没有用了,因为这个查了一天多,都要崩溃了,网上大部分都是用的这个,所以并没有意识到dll已经没有效果了。用nsProcess这个dll才是正确的。下面直接放代码,可用的:

Function .onInit
  nsProcess::_FindProcess "aidi.exe"
  Pop $R0
  IntCmp $R0 0 running no_running no_running
  running:
  MessageBox MB_ICONQUESTION|MB_YESNO "安装程序检测到 ${PRODUCT_NAME} 正在运行,是否强行关闭并继续安装?" IDYES dokill IDNO stopit
  no_running:
  GoTo endding
  dokill:
  nsProcess::_CloseProcess "aidi.exe"
  Pop $R0
  GoTo endding
  stopit:
  Abort
  endding:
  nsProcess::_Unload
FunctionEnd

;开始卸载时检查:
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除${PRODUCT_NAME} ,及其所有的组件?" IDYES +2
  nsProcess::_FindProcess "aidi.exe"
  Pop $R0
  IntCmp $R0 0 running no_running no_running
  running:
  MessageBox MB_ICONQUESTION|MB_YESNO "安装程序检测到 ${PRODUCT_NAME} 正在运行,是否强行关闭并继续卸载?" IDYES dokill IDNO stopit
  no_running:
  GoTo endding
  dokill:
  nsProcess::_CloseProcess "aidi.exe"
  Pop $R0
  GoTo endding
  stopit:
  Abort
  endding:
  nsProcess::_Unload
FunctionEnd

 

***************************************************************** *** nsProcess NSIS plugin v1.0 *** ***************************************************************** 2005 Shengalts Aleksander aka Instructor (Shengalts@mail.ru) Source function FIND_PROC_BY_NAME based upon the Ravi Kochhar (kochhar@physiology.wisc.edu) code Thanks iceman_k (FindProcDLL plugin) and DITMan (KillProcDLL plugin) for direct me Features: - Find/kill a process by name - Kill all processes with specified name (not only one) - The process name is case-insensitive - Win95/98/ME/NT/2000/XP support - Small plugin size (4,5 Kb) **** Output variables **** .r0-.r9 == $0-$9 .R0-.R9 == $R0-$R9 **** Find process **** nsProcess::FindProcess "[file.exe]" .r0 "[file.exe]" - Process name (e.g. "notepad.exe") .r0 - $0=0 Success $0=603 Process was not currently running $0=605 Unable to load PSAPI.DLL $0=606 Unable to identify system type $0=607 Unsupported OS $0=700 Unable to get procedure address from PSAPI.DLL $0=701 Unable to get process list, EnumProcesses failed $0=702 Unable to load KERNEL32.DLL $0=703 Unable to get procedure address from KERNEL32.DLL $0=704 CreateToolhelp32Snapshot failed **** Kill process **** nsProcess::KillProcess "[file.exe]" .r0 "[file.exe]" - Process name (e.g. "notepad.exe") .r0 - $0=0 Success $0=602 Not all processes terminated successfully $0=603 Process was not currently running $0=604 No permission to terminate process $0=605 Unable to load PSAPI.DLL $0=606 Unable to identify system type $0=607 Unsupported OS $0=700 Unable to get procedure address from PSAPI.DLL $0=701 Unable to get process list, EnumProcesses failed $0=702 Unable to load KERNEL32.DLL $0=703 Unable to get procedure address from KERNEL32.DLL $0=704 CreateToolhelp32Snapshot failed
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值