如何在 SQL CLR 项目中访问 WMI
我一直在做一个项目,需要我检索计算机的 CPU ID 以创建软件许可证,并将其与当前注册的许可证进行检查。
因此,我说了算,做了两个程序来实现这一目标。然后我需要将这个解决方案实现到我的 CLR 项目中。
我注意到我无法在 SQL 项目中添加 System.Management 引用。
因此,我无法像在其他 .NET 程序中那样访问上述控件来检索 CPU ID。
请我一周来一直在寻找解决方案,任何提示都会很有帮助。我见过有人在创建 SQL 程序集时包含 System.Management.dll,但我真的无法理解它是如何完成的。
I have a project i've been working on that requires me to retrieve the CPU ID of the computer to create a software licence and check it against the current licens registered.
So, said and done i made 2 programs to make this happen. Then i need to implement this solution into my CLR project.
I notice that i can't add System.Management reference in an SQL Project.
So therefor i can't access the said controls to retrieve the CPU ID as i did in my other .NET programs.
Please ive been searching for a solution for this for a week now and any hints would really help. Ive seen people including the System.Management.dll at creation of the SQL Assembly but i really cant grasp how its done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您最好的选择可能是创建一个 Web 服务来执行 WMI 操作并返回 cpu id。
或者,如果您想转向黑暗面,您可以查看 xp_cmdshel 和OLE 自动化对象来访问外部资源。
Your best bet would probably be to create a web service that does the WMI stuff and returns the cpu id.
Alternatively if you want to go over to the dark side you could you could look at xp_cmdshel and OLE Automation Objects to access external resources.
我认为您需要在 CLR 项目中启用“不安全”选项才能添加对 System.Management.dll 的引用。然后需要使用
CREATE ASSEMBLY
将System.Management.dll添加到数据库中。I think you need to enable the 'unsafe' option in your CLR project to be able to add a reference to System.Management.dll. The System.Management.dll will then need adding to the datbase using
CREATE ASSEMBLY
.