如何用Delphi轻松查找应用程序的早期实例?

更新于
2026-10-05 04:59:38
1阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计284个文字,预计阅读时间需要2分钟。

在Delphi中,我重写了一个VB6应用程序。它应该只运行一个实例。如何用最少的代码完成这项工作?在VB6中,我们只需一行代码+If App.PrevInstance Then+执行某些操作+End If+。在搜索时,我发现“

我在Delphi中重写了一个VB6应用程序.它应该只有一个实例在运行.如何用最少的代码完成这项工作?

在VB6中,我们只需要使用一行代码
>

If App.PrevInstance Then
‘Take some action
End If

在goggling我找到了解决方案,但它很长,我们不得不乱用.drp文件.

我不想那样做.

我想要更简单的东西.

我有一些代码:

var AppMutex: THandle; { .... } initialization // Create the mutex AppMutex := CreateMutex(nil, True, 'MY-APPLICATION-NAME'); if (AppMutex = 0) or (GetLastError = ERROR_ALREADY_EXISTS) then begin MessageDlg('My application is already running on this computer.'#13#10+ 'You should close the other instance before starting a new one.',mtError, [mbOK],0); Halt; end; finalization // Close the mutex CloseHandle(AppMutex);

但我确信@mghie所链接的帖子中的答案更有用/更丰富!

编辑:注意你可以把它变成一个小单元,然后在你的项目中使用那个单元.

本文共计284个文字,预计阅读时间需要2分钟。

在Delphi中,我重写了一个VB6应用程序。它应该只运行一个实例。如何用最少的代码完成这项工作?在VB6中,我们只需一行代码+If App.PrevInstance Then+执行某些操作+End If+。在搜索时,我发现“

我在Delphi中重写了一个VB6应用程序.它应该只有一个实例在运行.如何用最少的代码完成这项工作?

在VB6中,我们只需要使用一行代码
>

If App.PrevInstance Then
‘Take some action
End If

在goggling我找到了解决方案,但它很长,我们不得不乱用.drp文件.

我不想那样做.

我想要更简单的东西.

我有一些代码:

var AppMutex: THandle; { .... } initialization // Create the mutex AppMutex := CreateMutex(nil, True, 'MY-APPLICATION-NAME'); if (AppMutex = 0) or (GetLastError = ERROR_ALREADY_EXISTS) then begin MessageDlg('My application is already running on this computer.'#13#10+ 'You should close the other instance before starting a new one.',mtError, [mbOK],0); Halt; end; finalization // Close the mutex CloseHandle(AppMutex);

但我确信@mghie所链接的帖子中的答案更有用/更丰富!

编辑:注意你可以把它变成一个小单元,然后在你的项目中使用那个单元.