Reputation: 621
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.
Upvotes: 1
Views: 1081
Reputation: 189535
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.
Upvotes: 2