【发布时间】:2010-04-02 05:58:37
【问题描述】:
我是 NSIS 新手,我需要知道在卸载程序中如何检查应用程序(使用 C++ 编写)是否正在运行并在卸载前关闭它。
【问题讨论】:
标签: nsis
我是 NSIS 新手,我需要知道在卸载程序中如何检查应用程序(使用 C++ 编写)是否正在运行并在卸载前关闭它。
【问题讨论】:
标签: nsis
这里是使用NSProcess 的稍微友好的版本,它请求应用程序关闭而不是终止它(欧文的回答)
${nsProcess::FindProcess} "${APP_EXE}" $R0
${If} $R0 == 0
DetailPrint "${AppName} is running. Closing it down"
${nsProcess::CloseProcess} "${APP_EXE}" $R0
DetailPrint "Waiting for ${AppName} to close"
Sleep 2000
${Else}
DetailPrint "${APP_EXE} was not found to be running"
${EndIf}
${nsProcess::Unload}
【讨论】:
使用 NsProcess 插件。在此处下载 -> NSProcess
如何使用它?就这么简单:
${nsProcess::KillProcess} "${APP_EXE}" $R4
其中 APP_EXE 是您的应用程序的名称...
下载也会告诉你如何使用它... :)
【讨论】:
$R4 是什么意思?
根据应用程序,您有多种选择:
【讨论】:
ExecWait TaskKill /IM program_name /F
只需确保安装或卸载的第一件事是在以下 for 循环运行之前删除 %TEMP(或任何其他应用程序可写目录)中的所有 xyz.tmp 文件。无需插件。
!macro IsRunning
ExecWait "cmd /c for /f $\"tokens=1,2$\" %i in ('tasklist') do (if /i %i EQU xyz.exe fsutil file createnew $TEMP\xyz.tmp 0)"
IfFileExists $TEMP\xyz.tmp 0 notRunning
;we have atleast one main window active
MessageBox MB_OK|MB_ICONEXCLAMATION "XYZ is running. Please close all instances and retry." /SD IDOK
Abort
notRunning:
!macroEnd
【讨论】: