.NET 应用程序每机器/每用户许可
我即将为我的应用程序实现一个非常基本的许可功能。序列号可以按机器(或按操作系统)或按用户授予(对于 Windows Server 中的 CAL:如果我的应用程序由一台机器上的多个用户使用,或者由一个用户在多台机器上使用)机)。
对于每个操作系统的许可,我使用Win32_OperatingSystem。
对于每用户许可,我使用:
WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent(); if (当前身份!= null) { SecurityIdentifier userSid = currentIdentity.User.AccountDomainSid; Console.WriteLine(userSid); }
将获得的操作系统序列号或 SID 的哈希值存储在数据库中,与应用程序序列相关联;每次程序启动时,它都会查询服务器,发送操作系统 SN/SID 和应用程序序列的哈希值。
这样做是正确的还是完全错误的?它适用于每台 Windows 计算机吗? (例如,使用主板序列号是错误的)
I am about to implement a very basic licensing feature for my application. A serial number may be granted per-machine (or per-operating-system) or per-user (as for CAL in Windows Server: if my application is used by several users on one machine or if it is used by one user on several machines).
For per-operating-system licensing, I use SerialNumber of Win32_OperatingSystem.
For per-user licensing, I use:
WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent(); if (currentIdentity != null) { SecurityIdentifier userSid = currentIdentity.User.AccountDomainSid; Console.WriteLine(userSid); }
A hash of an obtained OS serial number or SID is then stored in the database, associated with application serial; each time the program starts, it queries the server, sending hash of OS SN/SID and application serial.
Is it a right thing to do it or is it completely wrong? Will it work on every Windows machine? (For example, using motherboard serial is wrong)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为你的方法有任何问题,因为我在工作中看到过类似的方法 - 但是我们使用操作系统 S/N 和硬件 ID 的组合来进行机器许可。我们的应用程序没有每用户许可,因此我无法就此提供建议。
请注意,您不应假设 WMI 返回的值采用任何特定格式(Win32_OperatingSystem 应该没问题,硬件 ID 并不总是没问题)
我遇到过代码接受硬件 ID 的错误假定采用特定格式,并且不考虑非字母数字字符(例如逗号和空格)的存在。
I don't see anything wrong with your approach, since I've seen a similar approach being used at work - however we use a combination of OS S/N and hardware IDs for machine licensing. Our apps don't have a per-user licensing, so I can't really advise on that.
Do note that you should not assume that values returned by WMI are in any particular format (Win32_OperatingSystem should be OK, IDs of hardware aren't always OK)
I've encountered bugs where the code accepting hardware IDs assumed a specific format and did not factor in the presence of non-alphanumeric characters such as commas and spaces.