Checking if the application is running in NSIS before uninstalling

泪湿孤枕 提交于 2019-12-22 04:59:14

问题


I am new to NSIS, and I need to know that in the uninstaller, how I can check if the application (which is in C++) is running and close it before uninstalling.


回答1:


Here is a slightly more friendly version for using NSProcess that requests the app to close rather than terminates it (Owen's answer)

${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}



回答2:


Use the NsProcess plugin. Download it here -> NSProcess
How to use it? As simple as:

${nsProcess::KillProcess} "${APP_EXE}" $R4

where APP_EXE is the name of your application...

The download will also tell you how to use it... :)




回答3:


Depending on the application, you have a couple of choices:

  • If your application has a window with a somewhat unique class name, you could use FindWindow
  • If your application creates a named kernel object (Mutex etc) you can check for it by calling the correct native win32 API with the system plugin
  • Use a 3rd party plugin like FindProcDLL



回答4:


Just make sure that the first thing that install or un-install does is to delete all xyz.tmp files in %TEMP (or any other app writable directory) before the below for loop runs. No plugins required.

!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


来源:https://stackoverflow.com/questions/2565215/checking-if-the-application-is-running-in-nsis-before-uninstalling

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!