It looks to me like you are on the right track. It is just a matter of determining which pieces to query.
This can be improved on, but its a start:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;
using System.IO;
namespace ConsoleApp2
{
class Program
{
public static bool GetComputerInfo(string machine, string win32object, string attributename)
{
bool bReturnValue = true;
try
{
ManagementScope scope = new ManagementScope($@"\\{machine}\ROOT\cimv2");
ObjectQuery query = new ObjectQuery($"SELECT * FROM {win32object}");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine($"{attributename} : {m[attributename]}");
}
}
catch(Exception ex)
{
Console.WriteLine($"{ex.Message}\n{ex.InnerException}\n{ex.StackTrace}");
bReturnValue = false;
}
return bReturnValue;
}
static void Main(string[] args)
{
string sTargetMachine = "localhost";
GetComputerInfo(sTargetMachine, "win32_ComputerSystemProduct", "IdentifyingNumber");
GetComputerInfo(sTargetMachine, "win32_bios", "SerialNumber");
GetComputerInfo(sTargetMachine, "win32_LocalTime", "Year");
GetComputerInfo(sTargetMachine, "win32_LocalTime", "Month");
GetComputerInfo(sTargetMachine, "win32_LocalTime", "Day");
GetComputerInfo(sTargetMachine, "win32_LocalTime", "Hour");
GetComputerInfo(sTargetMachine, "win32_LocalTime", "Minute");
GetComputerInfo(sTargetMachine, "win32_LocalTime", "Second");
Console.ReadLine();
}
}
}
Some other things I found useful while working on this, fire up Powershell
in powershell run the following to get a list of what is out there and queryable
get-wmiobject -List
Then based on what class / object you want to retrieve you can easily look at the available attributes, for example
PS> get-wmiobject win32_ComputerSystemProduct
IdentifyingNumber : XXXXXXX
Name : Latitude XXXX
Vendor : Dell Inc.
Version :
Caption : Computer System Product