Original link http://www.flighty.cn/html/bushu/20110402_115.html
If the program that we are installing or upgrading is running, the file will definitely replace the failure, and the following code can prompt the user to end the running program.
Need to use plugin FindProcDLL.dll, download path: http://nsis.sourceforge.net/FindProcDLL_plug-in
Http://files.cnblogs.com/files/z5337/FindProc.zip
Http://files.cnblogs.com/files/z5337/KillProcDll%26FindProcDll.zip
Check that Flighty.exe is running when you start the installation:
Function .onInit
; Close the process
Push $ R0
CheckProc:
Push "flighty.exe"
ProcessWork :: existsprocess
Pop $ R0
IntCmp $ R0 0 Done
MessageBox MB_OKCANCEL | MB_ICONSTOP "The installer detected that $ {PRODUCT_NAME} is running. $ \ R $ \ n $ \ r $ \ nClick OK to force close $ {PRODUCT_NAME} and continue with the installation. $ \ R $ \ nClick" Cancel "Exits the installer." IDCANCEL Exit
Push "flighty.exe"
Processwork :: KillProcess
Sleep 1000
Goto CheckProc
Exit:
Abort
Done:
Pop $ R0
FunctionEnd
Check that Flighty.exe is running when uninstalling starts:
Function un.onInit
MessageBox MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2 "Are you sure you want to completely remove $ (^ Name) and all its components?" IDYES +2
Abort
; Check if the program is running
FindProcDLL :: FindProc "flighty.exe"
Pop $ R0
IntCmp $ R0 1 0 no_run
MessageBox MB_ICONSTOP "The uninstaller detected $ {PRODUCT_NAME} is running, please close it before uninstalling!"
Quit
no_run:
FunctionEnd
Go NSIS: Check if the program is running when installing or uninstalling