I want to export the result of command 'wmic bios get' to a xml file. How can I read these data and add each data as a xml node?
Asked
Active
Viewed 291 times
-1
-
5What have you tried so far? – andyb952 Jul 17 '19 at 15:18
-
@andyb952 I found only how to execute batch file and get result of that – cj__ Jul 17 '19 at 15:21
-
@cj__ if you found how to execute a batch file and how to get the result, why don't you try executing the command as batch file, getting the results and maybe wrap it up with some kind of [XmlWriter](https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmlwriter?view=netframework-4.8)r? – FeRaaC Jul 17 '19 at 15:24
-
@FeRaaC Because I need to retrieve hw data of the server from client side – cj__ Jul 17 '19 at 15:28
-
Possible duplicate of [Windows Forms - How to return WMIC output into Textbox](https://stackoverflow.com/questions/32436424/windows-forms-how-to-return-wmic-output-into-textbox) – Lance U. Matthews Jul 17 '19 at 15:43
1 Answers
0
Something that actually had to do some time ago First you need class to handle requests by using wmi :
public class GetHW
{
public string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
{
string result = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
if (mo[wmiMustBeTrue].ToString() == "True")
{
//Only get the first one
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
}
}
return result;
}
public string identifier(string wmiClass, string wmiProperty)
{
string result = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
//Only get the first one
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
}
return result;
}
}
Then in your actual application query class like this :
GetHW HW = new GetHW();
Dictionary <string, string> data = new Dictionary<string,string();
data.Add("Manufacturer", HW.identifier("Win32_BIOS", "Manufacturer"));
data.Add("SMBIOSBIOSVersion", HW.identifier("Win32_BIOS", "SMBIOSBIOSVersion"));
data.Add("IdentificationCode", HW.identifier("Win32_BIOS", "IdentificationCode"));
data.Add("SerialNumber", HW.identifier("Win32_BIOS", "SerialNumber"));
data.Add("ReleaseDate", HW.identifier("Win32_BIOS", "ReleaseDate"));
data.Add("Version", HW.identifier("Win32_BIOS", "Version"));
Then do whatever you want with dictionary. It might be overkill for bios data, but it will allow you to pull other data if you ever need to - e.g. motherboard :
data.Add("Model", HW.identifier("Win32_BaseBoard", "Model"));
data.Add("Manufacturer", HW.identifier("Win32_BaseBoard", "Manufacturer"));
data.Add("Name", HW.identifier("Win32_BaseBoard", "Name"));
data.Add("SerialNumber", HW.identifier("Win32_BaseBoard", "SerialNumber"));
or CPU
data.Add("Unique ID", HW.identifier("Win32_Processor", "UniqueId"));
data.Add("ID", HW.identifier("Win32_Processor", "ProcessorId"));
data.Add("Name", HW.identifier("Win32_Processor", "Name"));
data.Add("Manufacturer", HW.identifier("Win32_Processor", "Manufacturer"));
data.Add("MaxClockSpeed", HW.identifier("Win32_Processor", "MaxClockSpeed"));
Edit : In case anyone ever need to - here is a a list of all win32 classes.

Vytautas Plečkaitis
- 851
- 1
- 13
- 19
-
-
Take a look at http://codemaverick.blogspot.com/2007/02/how-to-retrieve-management-information.html solution. The queries you might want to run are mosQuery = "SELECT * FROM Win32_DiskDrive"; and mosQuery = "SELECT * FROM Win32_DiskPartition"; – Vytautas Plečkaitis Jul 17 '19 at 15:49