使用COM+查询硬件信息自动化和 WMI
我正在开发一个具有更高信任度的 Silverlight 4(或可能 5)OOB 应用程序。我知道如何使用AutomationFactory查询WMI,但是是否可以查询硬盘序列号等硬件信息?请注意,这是一个具有较高信任度的 OOB 应用程序,因此不会带来安全风险。我将在我的 silverlight 应用程序上执行一些激活操作。
编辑:解决了!例如,您可以使用以下代码片段查询主板序列号:
using (dynamic SWbemLocator = AutomationFactory.CreateObject("WbemScripting.SWbemLocator"))
{
SWbemLocator.Security_.ImpersonationLevel = 3;
SWbemLocator.Security_.AuthenticationLevel = 4;
dynamic IService = SWbemLocator.ConnectServer(".", @"root\cimv2");
dynamic QueryResults = IService.ExecQuery(
@"SELECT Product, SerialNumber FROM Win32_BaseBoard");
dynamic QueryResult = QueryResults.ItemIndex(0);
string name = QueryResult.Product;
string value = QueryResult.SerialNumber;
MessageBox.Show(name + "\r\n" + value);
}
提前致谢。
I'm developing a Silverlight 4(or maybe 5) OOB Application with elevated trust. I know how to use AutomationFactory to query WMI, but is it possible to query hardware information such as HDD serial number? Note that this is a OOB app with elevated trust, so there is no security risk imposed. I'm going to perform some activation stuff on my silverlight app.
EDIT: Solved! For example, you can query mainboard serial number using the following code snippet:
using (dynamic SWbemLocator = AutomationFactory.CreateObject("WbemScripting.SWbemLocator"))
{
SWbemLocator.Security_.ImpersonationLevel = 3;
SWbemLocator.Security_.AuthenticationLevel = 4;
dynamic IService = SWbemLocator.ConnectServer(".", @"root\cimv2");
dynamic QueryResults = IService.ExecQuery(
@"SELECT Product, SerialNumber FROM Win32_BaseBoard");
dynamic QueryResult = QueryResults.ItemIndex(0);
string name = QueryResult.Product;
string value = QueryResult.SerialNumber;
MessageBox.Show(name + "\r\n" + value);
}
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从根本上讲,如果您可以在 VBScript 中完成此操作,那么您可以使用 OOB+Elevated trust 来完成此操作。 WMI 尤其常被通常用 VBScript 编写的管理脚本使用。因此,最好的方法是搜索您想要执行的操作的 VBScript 示例,然后使用
dynamic
类型简单地移植到 C#。Fundementally if you can do it in VBScript then you can do it with OOB+Elevated trust. WMI in particular is commonly used by administrative scripts usually written in VBScript. Hence the best approach is to search for VBScript examples of what you want to do then simply port to C# using the
dynamic
type.