网上的代码大同小异(见一楼回复),获取的cpuid有相同的,自然不可以用,不过有人用 delphi写的dll可以获取到真正的cpuid ,dll下载
http://d.download.csdn.net/down/945504/skniceDLL中只包含了一个函数
procedure GetCPUID(CPUID: PChar); stdcall; external 'CPUID_Util';调用它很简单,只要传入一个字符串指针,返回时就可以得到CPU的序列号了,是一个字符串DELPHI的调用举例如下
procedure TForm1.Button1Click(Sender: TObject);
var
  pc: Array[0..255] of Char;
begin
  GetCPUID(pc);
  Edit1.Text := StrPas(pc);
end;dll详细介绍 http://www.zjda07.cn/blog/article.asp?id=3
问题是我想在C#程序里调用这个dll来获取到cpuid,
我是这样用的 
  //定义DLL文件名,此文件路径要加到系统Path中
        private const string _fileDll = @"CPUID_Util.dll";
   //GetCPUID是 dll里面的一个方法
        private const string _FountionName = @"GetCPUID";
        [DllImport(_fileDll, EntryPoint = _FountionName, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        //C#中的申明
        public static extern string  GetCPUID(string id);
但是调用此方法,没有返回任何值,请高人指点,应该如何调用才能返回正确的cpuid

解决方案 »

  1.   

    下面是很常见的一种方法,但是两台不同的电脑获取的cpuid有可能是一样的
    using System;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Management;
    namespace ComLib.Win32.Hardware
    {
        public class Common
        {
            /// <summary>
            /// cpu序列号
            /// </summary>
            /// <returns></returns>
            public static string GetProcessorId()
            {
                string cpuInfo = "";
                ManagementClass cimobject = new ManagementClass("Win32_Processor");
                ManagementObjectCollection moc = cimobject.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
                    break;            }
                return cpuInfo;
            }
        }  }
      

  2.   

            [DllImport(_fileDll, EntryPoint = _FountionName, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] 
            //C#中的申明 
            public static extern string  GetCPUID(StringBuilder id); 
      

  3.   

    函数里边要改变那个参数,所以那个参数不能用string,只能用StringBuilder
      

  4.   

       /// <summary>
            /// 获取系统信息
            /// </summary>
            /// <param name="cpuinfo"></param>
            [DllImport("kernel32")]  
            public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);    [StructLayout(LayoutKind.Sequential)]
        public struct CPU_INFO
        {
            public uint dwOemId;                           //CPU的OEM-ID
            public uint dwPageSize;                        //CPU中的页面大小
            public uint lpMinimumApplicationAddress;
            public uint lpMaximumApplicationAddress;
            public uint dwActiveProcessorMask;
            public uint dwNumberOfProcessors;              //多少个CPU
            public uint dwProcessorType;                   //CPU类型
            public uint dwAllocationGranularity;
            public uint dwProcessorLevel;                  //CPU等级
            public uint dwProcessorRevision;
        } 用API呢?
      

  5.   

    api也不行,不过很感谢你的建议
      

  6.   

    据说CPU ID有些是一样的。AMD系列的。
      

  7.   

    [DllImport("CPUID_Util.dll", EntryPoint = "GetCPUID", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]//GetCPUID
            public static extern string CPUIDfromDll(StringBuilder _CPUID);
    arbond
      

  8.   

    引用楼主的代码://定义DLL文件名,此文件路径要加到系统Path中 
            private const string _fileDll = @"CPUID_Util.dll"; 
      //GetCPUID是 dll里面的一个方法 
            private const string _FountionName = @"GetCPUID"; 
            [DllImport(_fileDll, EntryPoint = _FountionName, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] 
            //C#中的申明 
            public static extern string  GetCPUID(string id); 
       该dll需要的是一个StringBuilder(一个可变的字符串类型。并不是一个string类型)
      解决办法: 
     
       //声明一个stringBuilder类型字符串
      StringBuilder strcpu=new StringBuilder();
       //将strcpu带入函数中
            GetCPUID(strcpu);
     //此时的strcpu已经是cpuid了
      Console.writeLine(strcpu);