由于程序正在运行,卸载失败。如何让 Inno Setup 在尝试删除之前检查正在运行的进程?

发布于 2024-08-08 03:58:56 字数 77 浏览 3 评论 0 原文

Inno Setup 在卸载过程中无法删除组件,因为我的程序仍在运行并且可执行文件无法删除。在允许卸载继续之前,如何让它检查它是否正在运行?

Inno Setup fails to remove components during uninstall cause my program is still running and the executable cannot be deleted. How do I have it check to see if it is running before allowing uninstall to proceed?

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

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

发布评论

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

评论(5

神仙妹妹 2024-08-15 03:58:56

检查这些

Inno Setup:使用 AppMutex 检测在任何用户会话中运行的实例

Inno 设置:应用程序正在运行吗?

Inno 设置:检测应用程序是否正在运行

有多种方法。如果您的程序定义了互斥体

[Setup]
AppMutex=MyMutexName

,或者在代码部分中指定了互斥体,

function CheckForMutexes (Mutexes: String): Boolean;

您还可以使用

function FindWindowByClassName (const ClassName: String): Longint; 

类名来获取窗口句柄并向其发送消息。

或者通过名称获取它

function FindWindowByWindowName (const WindowName: String): Longint;

或者您针对此特定用例使用多个 DLL 文件之一

或者阅读后自己做

如何在 Win32 中“干净地”终止应用程序

如何使用 Win32 API 枚举应用程序(此链接到德语版本,因为某种原因我找不到 KB175030 的英文版本,

或者尝试谷歌翻译版本KB175030-DE

KB175030 德国 -> EN

Check these

Inno Setup: Detect instances running in any user session with AppMutex

Inno Setup: Is application running?

Inno Setup: Detect if an application is running

There are several ways. If your program defines a mutex use

[Setup]
AppMutex=MyMutexName

or for a specified mutex in the Code section

function CheckForMutexes (Mutexes: String): Boolean;

You could also use

function FindWindowByClassName (const ClassName: String): Longint; 

to get the window handle by class name and send it messages.

Or get it by the name

function FindWindowByWindowName (const WindowName: String): Longint;

Or you use one of several DLL files for this specific use case

Or do it yourself after reading

How To Terminate an Application "Cleanly" in Win32

How To Enumerate Applications Using Win32 APIs (this one links to the german version as for some reason I can't find the english version of KB175030

or try the google translated version of the KB175030-DE

KB175030 DE -> EN

转身泪倾城 2024-08-15 03:58:56

我们使用了上述以外的其他方法。因为这是卸载,所以我们可以终止该应用程序并卸载它。
最简单的方法,当你不能使用 AppMutex 时:(与 真正杀死进程有关Windows

[UninstallRun]
Filename: "{cmd}"; Parameters: "/C ""taskkill /im <precessname>.exe /f /t"

希望有人能提供帮助。我为此寻找了很长时间。

We used an other way than described above. Because this is an uninstallation we can kill the application and unistall it.
The simpliest way, when u can't use AppMutex: (related to Really killing a process in Windows)

[UninstallRun]
Filename: "{cmd}"; Parameters: "/C ""taskkill /im <precessname>.exe /f /t"

Hope somebody will help this. I searched a long time for this.

风月客 2024-08-15 03:58:56

尝试这个解决方案!我在关闭应用程序时遇到了其他解决方案的问题,但 Inno Setup 仍然认为已安装的文件已被锁定。

请记住定义您的常量:

#define MyAppName "AppName"
#define MyAppExeName "AppName.exe"

[Code]
function InitializeUninstall(): Boolean;
  var ErrorCode: Integer;
begin
  ShellExec('open','taskkill.exe','/f /im {#MyAppExeName}','',SW_HIDE,ewNoWait,ErrorCode);
  ShellExec('open','tskill.exe',' {#MyAppName}','',SW_HIDE,ewNoWait,ErrorCode);
  result := True;
end;

主要支持此解决方案的原始来源< /a>.

Try this solution! I had issues with other solutions closing the app, but Inno Setup still thought the installed files were locked.

Remember to define your constants:

#define MyAppName "AppName"
#define MyAppExeName "AppName.exe"

[Code]
function InitializeUninstall(): Boolean;
  var ErrorCode: Integer;
begin
  ShellExec('open','taskkill.exe','/f /im {#MyAppExeName}','',SW_HIDE,ewNoWait,ErrorCode);
  ShellExec('open','tskill.exe',' {#MyAppName}','',SW_HIDE,ewNoWait,ErrorCode);
  result := True;
end;

Major props to the original source of this solution.

沉默的熊 2024-08-15 03:58:56

使用 AppMutex 指令 阻止卸载程序当应用程序运行时继续进行。

[Setup]
AppMutex=MyProgMutex

应用程序必须创建指令指定的互斥锁。有关示例,请参阅链接的 AppMutex 指令文档。


如果您想让卸载程序终止应用程序,请在应用程序仍在运行时使用以下代码:

function InitializeUninstall(): Boolean;
var
  ErrorCode: Integer;
begin
  if CheckForMutexes('MyProgMutex') and
     (MsgBox('Application is running, do you want to close it?',
             mbConfirmation, MB_OKCANCEL) = IDOK) then
  begin
    Exec('taskkill.exe', '/f /im MyProg.exe', '', SW_HIDE, 
         ewWaitUntilTerminated, ErrorCode);
  end;

  Result := True;
end;

与上面的 AppMutex 指令一样,应用程序必须创建 CheckForMutexes 调用。


请注意,对于安装程序,您不必编写此代码。安装程序内置重启管理器。
请参阅在 Inno Setup 中使用“taskkill /f /im”在(重新)安装之前终止进程

Use the AppMutex directive to prevent the uninstaller from proceeding, when an application is running.

[Setup]
AppMutex=MyProgMutex

The application has to create the mutex specified by the directive. See the linked AppMutex directive documentation for examples.


If you want to have the uninstaller kill the application, when it is still running, use this code instead:

function InitializeUninstall(): Boolean;
var
  ErrorCode: Integer;
begin
  if CheckForMutexes('MyProgMutex') and
     (MsgBox('Application is running, do you want to close it?',
             mbConfirmation, MB_OKCANCEL) = IDOK) then
  begin
    Exec('taskkill.exe', '/f /im MyProg.exe', '', SW_HIDE, 
         ewWaitUntilTerminated, ErrorCode);
  end;

  Result := True;
end;

As with the AppMutex directive above, the application has to create the mutex specified in the CheckForMutexes call.


Note that for installer, you do not have to code this. The installer has restart manager built-in.
See Kill process before (re)install using "taskkill /f /im" in Inno Setup.

月隐月明月朦胧 2024-08-15 03:58:56

也许添加此属性

CloseApplications=yes
它将查看所​​有 [Files] 和 [InstallDelete] 元素,并使用 Windows 重新启动管理器

https://jrsoftware.org/ishelp/index.php?topic=setup_closeapplications

perhaps add this property

CloseApplications=yes
it will look at all the [Files] and [InstallDelete] elements and work using windows restart manager

https://jrsoftware.org/ishelp/index.php?topic=setup_closeapplications

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