Retrieve the operating Systems Details using WMI

using this Function we can Retrieve the Operating systems details.





private void getOSDetails()
{

ManagementObjectSearcher objMOS = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");

foreach (ManagementObject objManagemnet in objMOS.Get())
{
try
{
using(StreamWriter objStreamWriter = new StreamWriter(@"D:\osDetails.txt"))
{
objStreamWriter.WriteLine("======================================================================");
objStreamWriter.WriteLine(" Operating System Details ");
objStreamWriter.WriteLine("======================================================================");

objStreamWriter.WriteLine("BootDevice :" + Convert.ToString(objManagemnet.GetPropertyValue("BootDevice")));
objStreamWriter.WriteLine("BuildNumber :" + Convert.ToString(objManagemnet.GetPropertyValue("BuildNumber")));
objStreamWriter.WriteLine("Caption :" + Convert.ToString(objManagemnet.GetPropertyValue("Caption")));
objStreamWriter.WriteLine("CountryCode :" + Convert.ToString(objManagemnet.GetPropertyValue("CountryCode")));
objStreamWriter.WriteLine("Description :" + Convert.ToString(objManagemnet.GetPropertyValue("Description")));
objStreamWriter.WriteLine("InstallDate :" + Convert.ToString(objManagemnet.GetPropertyValue("InstallDate")));


objStreamWriter.WriteLine("LastBootUpTime :" + Convert.ToString(objManagemnet.GetPropertyValue("LastBootUpTime")));
objStreamWriter.WriteLine("Manufacturer :" + Convert.ToString(objManagemnet.GetPropertyValue("Manufacturer")));
objStreamWriter.WriteLine("Name :" + Convert.ToString(objManagemnet.GetPropertyValue("Name")));
objStreamWriter.WriteLine("NumberOfUsers :" + Convert.ToString(objManagemnet.GetPropertyValue("NumberOfUsers")));
objStreamWriter.WriteLine("Organization :" + Convert.ToString(objManagemnet.GetPropertyValue("Organization")));
objStreamWriter.WriteLine("SerialNumber :" + Convert.ToString(objManagemnet.GetPropertyValue("SerialNumber")));

objStreamWriter.WriteLine("RegisteredUser :" + Convert.ToString(objManagemnet.GetPropertyValue("RegisteredUser")));
objStreamWriter.WriteLine("SystemDirectory :" + Convert.ToString(objManagemnet.GetPropertyValue("SystemDirectory")));
objStreamWriter.WriteLine("SystemDrive :" + Convert.ToString(objManagemnet.GetPropertyValue("Name")));
objStreamWriter.WriteLine("Version :" + Convert.ToString(objManagemnet.GetPropertyValue("Version")));
objStreamWriter.WriteLine("WindowsDirectory :" + Convert.ToString(objManagemnet.GetPropertyValue("WindowsDirectory")));

}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}


}




Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: