Skip to main content

monolith[This blog is part of a larger series, to find more parts in the series please see the Series Index]

For today we will be looking at a very useful class ComputerInfo, which provides a small set of information on the computer. It doesn’t provide a lot of info but the information it provides are key:

  • OSFullName: The “nice” name for the OS – like Windows 7 Ultimate
  • OSVersion: The OS version number
  • OSPlatform: The OS platform
  • TotalPhysicalMemory, AvailablePhysicalMemory, TotalVirtualMemory, AvailableVirtualMemory: Memory usage information
  • InstalledUICulture: The culture that was used during the install, this is the exact same as System.Globalization.CultureInfo.InstalledUICulture
ComputerInfo info = new ComputerInfo();
Console.WriteLine("You are running {0} ({1})", info.OSFullName, info.OSVersion);
Console.WriteLine("\t this is built on the {0} platform.", info.OSPlatform);

UInt64 usedPhysical = info.TotalPhysicalMemory - info.AvailablePhysicalMemory;
UInt64 usedVirtual = info.TotalVirtualMemory - info.AvailableVirtualMemory;

Console.WriteLine("Memory Information in Mb (Available | Used | Total)");
Console.WriteLine("\t  Virtual: {0} | {1} | {2}", info.AvailableVirtualMemory / 1048576, usedVirtual / 1048576, info.TotalVirtualMemory / 1048576);
Console.WriteLine("\t Physical: {0} | {1} | {2}", info.AvailablePhysicalMemory / 1048576, usedPhysical / 1048576, info.TotalPhysicalMemory / 1048576);

Console.WriteLine("You are running the following culture {0}", CultureInfo.CurrentCulture.EnglishName);
if (CultureInfo.CurrentCulture != info.InstalledUICulture)
{
    Console.WriteLine("BUT you installed with {0}", info.InstalledUICulture.EnglishName);
}
else
{
    Console.WriteLine("and you installed with that culture too");
}

This gives us:

image

This is isn’t the only way to get computer information, there is plenty in other locations in the framework – for example the System.Environment class from the mscorlib assembly has things like:

  • Environment.Is64BitOperatingSystem
  • Environment.Is64BitProcess
  • Environment.MachineName
  • Environment.OSVersion
  • Environment.ProcessorCount
  • Environment.Version