如何检测在另一个工作站上运行的同一 Win32 应用程序的另一个实例?
我有一个小型应用程序,个人使用免费,但企业使用需要付费许可证。
在企业环境中,我的应用程序很可能会在多个工作站上运行。 如果是免费软件版本,我想显示一条不引人注目的消息。 (并继续)
它不必是防弹的,如果不可能(即防火墙),那么应用程序应该继续。 我不想让用户设置某种中央服务来跟踪实例。 我不想惹恼我的用户(尤其是付费用户*g*)
有什么方法可以实现这种功能吗?
我记得旧版本的 Dreamweaver 有这种功能。 您不能在同一网络中多次运行它。
I have a small application, which is free for personal use, but requires a paid license for corporate use.
It is most likely that in a corporate environment my application will run on multiple workstations. If it is the freeware version, I want to show an unobtrusive message. (and continue)
It doesn't have to be bulletproof, if it is not possible (i.e. firewall) then the application should just continue. And I don't want to make the user set up some kind of central service to track the instances. I don't want to annoy my users (especially not the paying ones *g*)
Is there any way to achive this kind of functionality?
I remember an older version of Dreamweaver had this kind of feature. You couldn't run it more than once in the same network.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一种方法:侦听特定端口上的 UDP 广播。 让每个实例在此端口上向本地网络发送广播 UDP 数据包。 如果应用程序收到这样的数据包,并识别其结构,它就知道其他实例正在运行。
您可以包含许可证详细信息,以避免在使用两个有效许可证时出现消息。
广播通常不会被路由,因此这只适用于本地网络。 (用户也可以通过防火墙完全禁用它......但如果您使用一些标准端口,如 53 (DNS),它不会被阻止)。
另一种方法是使用自定义服务器,该服务器了解世界各地所有正在运行的实例;-)
One way: Listen for UDP broadcast on specific ports. Let each instance send broadcast UDP packet on this port to local network. If application receives such packet, and recognizes its structure, it knows that other instance is running.
You can include license details to avoid messages if two valid licenses are used.
Broadcasts usually aren't routed, so this works on local network only. (And user can disable it completely via firewall too... but if you will use some standard port like 53 (DNS), it won't be blocked).
Other way is to use custom server, which is informed about all running instances around the world ;-)
有两种主要方法可以实现此目的:
首先,您可以在每个工作站上设置一个小型服务器应用程序,与网络上的其他工作站进行通信(我个人会使用 Bonjour 进行发现,但还有其他选择)。 这里的缺点是,与选项 #2 相比,您需要编写更多的代码来完成这项工作。
第二种(可能更简单)是使用 WMI 枚举其他工作站上的进程(同样,可能使用类似 Bonjour 的系统进行发现),并找到在其他计算机上运行的进程。 这样做的缺点是您的枚举代码需要所有计算机上的权限才能进行搜索。
There are two primary ways to achieve this:
First, you can set up a small server application on each workstation that communicates with other workstations on the network (personally I would use Bonjour for discovery, but there are other options). The drawback here is that you're going to write quite a bit more code to make this work than option #2.
Second (probably simpler) would be to use WMI to enumerate processes on other workstations (again, probably use a Bonjour-like system for discovery), and find your process running on other machines. The drawback to this is that your enumeration code will require privileges on all machines to conduct the search.
当应用程序启动时,它会在特定端口上发送 UDP 广播。 这将仅限于本地子网,并且可能无法通过防火墙。 这就是“还有其他人在运行吗?还是我可以开始?” 询问。
如果没有响应,应用程序将正常启动,侦听此 UDP 广播。 如果它看到一个,它会响应一个“我已经在运行;你无法启动”数据包。
刚刚启动的应用程序收到此响应数据包,然后拒绝启动或(如果您不想那么严格)向用户显示警告。
您需要在初始请求中包含产品 ID 和许可证密钥(或哈希值),以便您可以在同一网络上拥有多个许可证。 响应可能需要其中包含计算机名称,以便第二个用户可以找到第一个用户并询问他们是否确实需要使用该应用程序。
When the application starts, it sends out a UDP broadcast on a specific port. This will be restricted to the local subnet, and might not make it through firewalls. This is the "is anyone else running, or can I start?" query.
If there are no responses, the application starts as normal, listening for this UDP broadcast. If it sees one, it responds with an "I'm already running; you can't start" packet.
The application that's just started receives this response packet and then refuses to start or (if you don't want to be that strict) displays a warning to the user.
You'd want to include the product ID and license key (or a hash) in the initial request, so that you can have more than one license on the same network. The response probably wants the machine name in it, so that the second user can go and find the first user and ask if they really need to use the application.
邪恶公司的解决方案:
让应用程序在每次启动时回拨。 如果多个许可证申请被唤醒,请告诉它不要这样做。 如果没有互联网连接,则根本不要启动。
Evil corporation solution:
Have the application call home every time it starts. If more than one application for a license wakes up, tell it not to. If there is no internet connection, don't start at all.