I need to know how I can get RAM (Physical memory) serial number. I am using C# and I used WMI to get Hardware information but serial Number return null on another computers. I want to know how can I get it and work on any computer (not WMI) and if there is no another way can I write it in C++ and make connection between this function and my application?
This is some of my code: WqlObjectQuery Memory3_objectQuery = new WqlObjectQuery("Select * from Win32_PhysicalMemory"); ManagementObjectSearcher Memory3_Searcher = new ManagementObjectSearcher(Memory3_objectQuery); foreach (ManagementObject MO2 in Memory3_Searcher.Get()) {
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@Component_Type", "RAM");
try
{
Model = MO2["Model"].ToString();
if (Model != null)
{
cmd.Parameters.AddWithValue("@Model", Model);
}
else { }
}
catch (NullReferenceException) { }
try
{
Capacity = MO2["Capacity"].ToString();
if (Capacity != null)
{
cmd.Parameters.AddWithValue("@Capacity", Capacity);
}
else { }
}
catch (NullReferenceException)
{ }
try
{
Serial = MO2["SerialNumber"].ToString();
if (Serial != null)
{
cmd.Parameters.AddWithValue("@SerialNumber", Serial);
}
else { }
}
catch (NullReferenceException)
{
}
try
{
Manufacturer = MO2["Manufacturer"].ToString();
if (Manufacturer != null)
{
cmd.Parameters.AddWithValue("@Manufacturer", Manufacturer);
}
else { }
}
catch (NullReferenceException)
{
}
// Console.WriteLine("Serial Number Bank" + count + ": " + s);
try
{
s = MO2["MemoryType"].ToString();
if (s.Equals("21"))
{
s = "DDr2";
cmd.Parameters.AddWithValue("@Memory_Type", s);
}
else if (s.Equals("20"))
{
s = "DDr";
cmd.Parameters.AddWithValue("@Memory_Type", s);
}
else if (s.Equals("17"))
{
s = "SDRAM";
cmd.Parameters.AddWithValue("@Memory_Type", s);
}
}
catch (NullReferenceException) { }
cmd.Parameters.AddWithValue("@Computer_Name", myHost);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
//SEE http://licensetoolkit.com/blog/hardware-identification-using-ram/
//using System.Management;
public static void OutputRamInformation()
{
// Create our WMI searcher to do our query
ManagementObjectSearcher searcher = new
ManagementObjectSearcher( "select * from Win32_PhysicalMemory" );
// Now loop through all the item found with the query
int ram = 1;
foreach ( ManagementObject obj in searcher.Get() )
{
Console.WriteLine( String.Format( "RAM #{0}:" , ram ) );
// Now step through each of the properties and output their values
foreach ( PropertyData property in obj.Properties )
{
if ( property.Value != null )
{
Console.WriteLine( property.Name + " = " +
property.Value.ToString() );
}
}
Console.WriteLine( "---------------------------------" );
// Increment our ram chip count
ram++;
}
// Wait for a keypress before continuting
Console.WriteLine( "Press any key to continue..." );
Console.ReadKey();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With