在 ASP.NET 应用程序中获取卷序列号的最佳方法?
我正在开发一个 ASP.Net 应用程序,它是现有 winforms 桌面应用程序的 Web 版本。桌面应用程序读取定义启用功能的许可证文件以适应其行为。为了将应用程序锁定到特定机器,许可证文件的设置之一是第一系统卷的序列号。启动时,应用程序会检查许可证文件中的序列号是否与卷序列号匹配。获取卷序列号是通过 PInvoking kernel32.dll 的 GetVolumeInformation
函数完成的。
然而,在asp.net版本中,使用本地服务或本地网络身份的标准应用程序池没有PInvoke的权限,导致无法检查许可证文件是否有效。如何在应用程序启动时检查许可证?
我可以想到以下替代方案:
- 用不需要特殊权限来获取卷序列号的方法替换 PInvoke(WMI 就是这种情况吗?)
- 将所有许可证检查代码放在单独的程序集中并将其安装到GAC 让它执行提升,
- 在安装过程中为我的应用程序创建一个具有管理员身份的应用程序池
第一个解决方案将是最好的,但我不知道是否可行。
我还有其他的可能性吗?每种方法的优点和缺点是什么?哪一个最好?
I work on an ASP.Net application which is a web version of an already existing winforms desktop application. The desktop application reads a license file defining enabled features to adapt its behavior. To lock the application to a specific machine, one of the setting of the license file is the serial number of the first system volume. At startup the application checks that the serial number in the license file matches the volume serial number. Getting the volume serial number is done by PInvoking kernel32.dll's GetVolumeInformation
function.
However in the asp.net version a standard application pool using a local service or local network identity does not have permission to PInvoke, resulting in the impossibility to check the license file is valid. How can I check the license at the application startup?
I can think of the following alternatives:
- replacing the PInvoke by a method which does not require special permissions to get the volume serial number (is it the case with WMI?)
- putting all the license checking code in a separate assembly and install it to the GAC to have it executed elevated
- creating an application pool with administrator identity just for my application during the installation process
The first solution would be the best but I don't know if it is possible.
Have I other possibilities? What are the pros and cons of each method? Which one is the best?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用WMI。 Win32_Volume 类具有卷的序列号。你可以使用这样的东西:
I suggest using WMI. The Win32_Volume class has the serial number of the volume. You can use something like this: