前两天刚收到的一个VB邮件,此免费邮件列表的订退,请访问http://www.sqdnc.com利用API测试计算机CPU的类型和序号 
在一个模块中声明以下函数:
Public Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type
Public Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
在窗体中加入以下代码,运行程序!Dim sys As SYSTEM_INFOPrivate Sub Command1_Click()
GetSystemInfo sys
Label1.Caption = "Cpu的类型为:" & sys.dwProcessorType
End SubPrivate Sub Command2_Click()
GetSystemInfo sys
Label2.Caption = "Cpu的序号为:" & sys.dwNumberOrfProcessors
End SubPrivate Sub Command3_Click()
Dim s
s = String$(200, 0)
Dim dl
Dim sz
sz = 199
dl = GetComputerName(s, sz)
Label3.Caption = dl
End Sub

解决方案 »

  1.   

    如果只想用VB,可以使用WMI得到。如果想支持多种操作系统,需要其他的DLL支持(C写得)。
      

  2.   

    Private Sub Command2_Click()
    GetSystemInfo sys
    Label2.Caption = "Cpu的序号为:" & sys.dwNumberOrfProcessors   ********这个很搞笑啊,这是说CPU的数目,而不是序列号!*******
    End Sub
      

  3.   

    redsoft(牛牛) ,你好,uguess(uguess)先生对代码提出了异议,到底有无错误,如何改?我是想用它给程序加密的。
      

  4.   

    http://ygyuan.go.163.com/
    http://ygyuan.3322.net/
    下载并安装"雁留声名录系统",然后你就可以得到第一个硬盘的序列号了!Private Declare Function GetDiskSN Lib "GetDiskSN.dll" (ByVal lpszSN As String) As DoubleDim s  As String
    s = String(1024, Chr(0))
    GetDiskSN (s)
    s = Trim(Replace(s, Chr(0), ""))
    msgbox s 
      

  5.   

    同意 y1g1y1(袁飞☆曾经沧海难为水,除却VB不是云☆) 的答案
      

  6.   

    http://www.csdn.net/expert/topic/455/455995.xml?temp=.5781671
      

  7.   

    不好意思,因本人出差在外,手头没有VB,贴之前我也未经测试,今天用EXCEL中的VBA试了一下,果然得到的是CPU的数目。
      

  8.   

    记不清了,msdn 中查get*volumeinfo??这么个Api函数!
      

  9.   


        下 面 的 这 个 例 子 是 使 用 GetVolumeInformation获 得 磁 盘 的 序 列 号 : 
        Private Declare Function GetVolumeInformation Lib _ 
         "kernel32.dll" Alias "GetVolumeInformationA" (ByVal _ 
         lpRootPathName As String, ByVal lpVolumeNameBuffer As _ 
         String, ByVal nVolumeNameSize As Integer, _ 
         lpVolumeSerialNumber As Long, lpMaximumComponentLength _ 
         As Long, lpFileSystemFlags As Long, ByVal _ 
         lpFileSystemNameBuffer As String, ByVal _ 
         nFileSystemNameSize As Long) As Long 
         
         Function GetSerialNumber(strDrive As String) As Long 
         Dim SerialNum As Long 
         Dim Res As Long 
         Dim Temp1 As String 
         Dim Temp2 As String 
         Temp1 = String$(255, Chr$(0)) 
         Temp2 = String$(255, Chr$(0)) 
         Res = GetVolumeInformation(strDrive, Temp1, _ 
         Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2)) 
         GetSerialNumber = SerialNum 
         End Function 
        调 用 时 使 用 GetSerialNumber("C:\")就 可 以 了 。 
    我用上面的代码在两台不同的计算机上得出的("C:\")盘的序列号是完全相同的,这是为什么啊?盼高手指教。
      

  10.   

    http://www.hktk.com/soft/program/article/vb/vb206.html
    用VB为软件增加注册功能 
    郭瑞刚 对你可能有点用 不过这个代码好象也有点问题
      

  11.   

    Private Type OSVERSIONINFO
            dwOSVersionInfoSize As Long
            dwMajorVersion As Long
            dwMinorVersion As Long
            dwBuildNumber As Long
            dwPlatformId As Long
            szCSDVersion As String * 128      '  Maintenance string for PSS usage
    End Type
    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Const VER_PLATFORM_WIN32_NT = 2
    Private Const VER_PLATFORM_WIN32_WINDOWS = 1
    Private Const VER_PLATFORM_WIN32s = 0Dim len5 As Long, aa As Long
        Dim cmprName As String
        Dim osver As OSVERSIONINFO
        '取得Computer Name
        cmprName = String(255, 0)
        len5 = 256
        aa = GetComputerName(cmprName, len5)
        cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1)
        Computer = cmprName        '取得CPU端口号
        Set CPUs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("select * from Win32_Processor")
        For Each mycpu In CPUs
          bbb = mycpu.ProcessorId
        Next
      

  12.   

    http://www.csdn.net/Expert/TopicView1.asp?id=928731