卸载前检查应用程序是否在 NSIS 中运行

发布于 2024-08-27 15:19:12 字数 63 浏览 5 评论 0原文

我是 NSIS 新手,我需要知道在卸载程序中,如何检查应用程序(C++ 中的)是否正在运行并在卸载之前将其关闭。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜`诱少女 2024-09-03 15:19:12

这是一个稍微更友好的版本,使用 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}

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}
幻想少年梦 2024-09-03 15:19:12

使用 NsProcess 插件。在这里下载 -> NSProcess
如何使用?就像简单一样:

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

其中 APP_EXE 是您的应用程序的名称...

下载还将告诉您如何使用它...:)

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... :)

開玄 2024-09-03 15:19:12

根据应用程序,您有多种选择:

  • 如果您的应用程序有一个带有某种唯一类名的窗口,您可以使用 FindWindow
  • 如果您的应用程序创建了一个命名的内核对象(互斥体等),您可以通过调用正确的方法来检查它带有系统插件的本机 win32 API
  • 使用第 3 方插件,例如 FindProcDLL

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
无边思念无边月 2024-09-03 15:19:12

只需确保安装或卸载的第一件事是在运行下面的 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文