shijin February 2016

How to display ram type in output using c#?

I am trying to display the size and type of the ram in my project. I am using windows 7 32 bit system. I was success in printing size of ram using

ulong mem = ulong.Parse(CI.TotalPhysicalMemory.ToString());
Console.WriteLine("Total Physical Memory:{0}",mem/(1024*1024) + " MB");

But cannot display type of ram using :

public static string GetMemoryType(int MemoryType)
 {   
   switch (MemoryType)       
   {
      case 20:
         return "DDR";
         break;

      case 21:
         return "DDR-2";
         break;    
      default:
          if (MemoryType == 0 || MemoryType > 22)
            return "DDR-3";     
          else
            return "Other";
          break;
  }
}

Please help me to solve this.

Answers


Kutty Rajesh Valangai February 2016

simple snippet

add namespaces manually by

Right-click References -->.NET---> on the right and manually add System.Management --->add

using System.Management;
using System.Management.Instrumentation;

and code

 public string RAM_Type()
            {

                int type=0;
                var searcher = new ManagementObjectSearcher("Select * from Win32_PhysicalMemory");
                foreach (ManagementObject obj in searcher.Get())
                {
                   type = Int32.Parse(obj.GetPropertyValue("MemoryType").ToString());

                }

                switch (type)
                {
                    case 20:
                        return "DDR";
                        break;
                    case 21:
                        return "DDR-2";
                        break;
                    case 17:
                        return "SDRAM";
                        break;
                    default:
                        if (type == 0 || type > 22)
                            return "DDR-3";
                        else
                            return "Unknown";
                }

            }

Post Status

Asked in February 2016
Viewed 1,785 times
Voted 4
Answered 1 times

Search




Leave an answer