NSIS版本:3.0.6
NsProcess版本:1.6
例子:檢查Excel程序是否在運行
1、下載NsProcess
下載NsProcess,將nsProcess.dll、nsProcessW.dll拷貝到NSIS的插件路徑C:\Program Files (x86)\NSIS\Plugins\x86-ansi。
2、編寫檢查腳本
在安裝腳本中編寫Macro,在檢測到進程存在后彈出提示,並退出安裝或卸載。
!macro FindProcess StrCpy $1 "excel.exe" nsProcess::_FindProcess "$1" Pop $R0 ${If} $R0 = 0 MessageBox MB_OK|MB_ICONSTOP "程序檢測到 Excel 正在運行,請關閉Excel重新開始!" IDOK Abort ${EndIf} !macroend
3、在Function .onInit和un.onInit中分別調用
Function .onInit !insertmacro FindProcess FunctionEnd Function un.onInit !insertmacro FindProcess MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你確實要完全移除 $(^Name) ,其及所有的組件?" IDYES +2 FunctionEnd
4、在安裝或者卸載程序啟動時先檢測進程是否存在,如果存在提示並退出執行
參考:
Function Call in .onInit and un.oninit - NSIS Forums (nsis-dev.github.io)