在Windows上,每个shell会话将应用程序限制为一个实例 [英] Restrict application to one instance per shell session on Windows
问题描述
有很多解决方案可以限制应用程序运行两次.通过进程名称搜索,使用命名的互斥锁等.但是,如果我想将应用程序限制在shell会话中,那么所有这些方法都将无效.
There are a lot of solutions for restricting an application from running twice. Searching by process name, using a named mutex etc. But I all of these methods don't work if I want to restrict my application to the shell session.
用户在Windows上的登录会话和shell可能不止一个(对吗?)?如果是这样,我希望能够在每个Shell会话中运行我的应用程序的一个实例,但只允许一个实例.
A user may have more than login session and shell on windows (right?)? If this is true I want to be able to run one instance of my application in every shell session but allow only one.
是否有一种方法可以获取可用于互斥体名称的shell标识符?
Is there a way to get a shell identifier which could then be put into the mutex name?
推荐答案
您可以创建本地(仅会话)或全局(整个系统)互斥体.请参见 http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx 了解更多信息.寻找全球和本地.
You can create local (session only) or global (whole system) mutexes. See http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx for more info. Look for global and local.
这篇关于在Windows上,每个shell会话将应用程序限制为一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!