似乎 AppMutex
指令对我的安装脚本不起作用。
我关注这篇文章:http://www.jmedved.com/2012/06/mutex-for-innosetup/
这是我的应用程序的 C# 代码:
private static string appGuid = "Loader";
...
bool createdNew;
var mutexSec = new MutexSecurity();
mutexSec.AddAccessRule(
new MutexAccessRule(
new SecurityIdentifier(WellKnownSidType.WorldSid, null),
MutexRights.FullControl, AccessControlType.Allow));
using (var setupMutex = new Mutex(false, @"Global\"+appGuid, out createdNew, mutexSec))
{
if (!createdNew)
{
MessageBox.Show(
"Application already running.", "Loader", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Loader(args));
}
在 Inno Setup 脚本中我只有:
AppMutex=Loader
但是,如果应用程序正在运行,安装程序也可以运行。
我还尝试检查是否真的存在互斥锁,因此我使用进程资源管理器查找应用程序处理程序,我得到了这个:
AppMutex=Loader
Mutant \BaseNamedObjects\Loader
我错过了什么?
最佳答案
由于您已经在应用程序的 Global\
命名空间中创建了互斥体,因此您也应该明确地为 AppMutex
执行相同的操作。 Inno Setup 脚本中的 mutex 名称,因为如果省略命名空间前缀,则不会在全局命名空间中创建互斥对象。所以使用这个脚本行应该可以解决你的问题:
[Setup]
AppMutex=Global\Loader
关于c# - AppMutex 不适用于 Inno Setup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21120122/