我如何获得ram序列号? [英] How can i get ram serial number ?

查看:140
本文介绍了我如何获得ram序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何获得RAM(物理内存)序列号。我正在使用C#,我使用WMI获取硬件信息,但序列号在另一台计算机上返回null。我想知道如何在任何计算机(而不是WMI)上使用它并且如果没有其他方法可以用C ++编写并在此函数和我的应用程序之间建立连接?



这是我的一些代码:

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();

}

推荐答案

我不认为这是你的代码的问题。虽然通过wmi提供内存序列号很常见,但对于制造商来说并非绝对必须。您不应该仅仅依赖此信息,因为您可以从特定计算机收集多个序列号和部件号,SID-s并将它们合并到散列中。如果你不依赖单个值 - 如果由于某种原因缺少任何一个值就没有问题。



但是尝试将激活策略绑定到设备很少改变。内存模块经常升级。



环顾这里: http://licensetoolkit.com / blog / [ ^ ]



但是SA对于一件事是正确的:一般来说,如果一个软件购买的软件在配置升级后无法工作,那么你至少是不公平的。您应该通过Web提供一种简单的方法,使用户能够在系统更改后重新激活产品。这是一个贸易政策的问题...
I don't think it is a problem of your code. Although it is common to provide memory serial number via wmi, it is not absolutely a must for the manufacturers. You should not rely solely on this information, since you can gather several serial numbers and part numbers, SID-s from the specific machine and merge them in a hash. If you don't depend on a single value - you have no problem if any of them is missing for some reason.

But try to bind your activation strategy to devices that are rarely changed. Memory modules are upgraded often.

Look around here: http://licensetoolkit.com/blog/[^]

But SA is right about one thing: in general, you would be at least unfair if a software bought by one would not work after configuration upgrade. You should provide an easy way over web to enable user to re-activate the product after system change. This is a matter of trade policy...


虽然我不知道你的代码出了什么问题,如果你想用C ++编写它你可以用 P / Invoke [ ^ ]通过C#。



(作为附注,如果它适用于您的机器但不适用于他们的机器,可能需要以管理员身份运行吗?)
While I don't know what's going wrong in your code, if you want to write it in C++ you can call it with P/Invoke[^] through C#.

(As a side note, if it works on your machine but not theirs, maybe they need to run it as an administrator?)


/*This C# method will return a string containing the PartNumber, SerialNumber, and Capacity properties for all of the RAM installed in the system:

*/
//using System.Management;
public static string GetRamInformation()
{
    string ram = String.Empty;
    // 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
    foreach ( ManagementObject obj in searcher.Get() )
    {
        object part = obj[ "PartNumber" ];
        object serial = obj[ "SerialNumber" ];
        object capacity = obj[ "Capacity" ];
        ram += ( String.IsNullOrEmpty( ram ) ? "" : " ~~ " ) +
         ( part == null ? String.Empty : part.ToString().Trim() ) + " - " +
         ( serial == null ? String.Empty : serial.ToString().Trim() ) + " - " +
         ( capacity == null ? String.Empty : capacity.ToString().Trim() );
    }
    return ram;
}


这篇关于我如何获得ram序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆