WMI is a powerful tool provided by Microsoft that provides component information and notificaiton. Below is a snippet on how you can query WMI to retrieve the Dell Service Tag of a single computer. You can easily extend this sample via Directory Service (LDAP) to query all PCs in your network.
Please Note: Make sure you add a reference to System.Management and place using System.Management; to the top of your code file.
We start by setting the computerName string to you PC’s name. You can press and hold window key on your keyboard then press the Pause/Break key to load the System Properties . If Windows XP you’ll want to click on the Computer Name tab. On Windows 7/Vista machines you will see the computer name right on System window that pops up somewhere near in the middle of the screen.
string computerName = “<Your PC Name>”;
Next you’ll want to create a ManagementScope object by passing in the Management Path to the constructor (which concatenates the PC name).
ManagementScope scope = new ManagementScope(@”\\” + computerName + @”\root\cimv2″);
Next, you create an ObjectQuery object which accepts a query that looks very much like a standard T-SQL query. Click here to view reference list that’ll help you build your own queries.
ObjectQuery query = new ObjectQuery(“Select SerialNumber From Win32_SystemEnclosure”);
Next you’ll create a ManagementObjectSearcher object that will be used to actually execute the query.
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
The Get() method returns the results into the ManagementObjectCollection object.
ManagementObjectCollection objColl = searcher.Get();
The rest is simple, you loop through each element in the collection and retrieve the SerialNumber since this is where Dell Stores their Service Tags.
foreach (ManagementObject o in objColl)
Console.WriteLine(computerName + “:” + o[“SerialNumber”].ToString());