zoukankan      html  css  js  c++  java
  • VB6 獲取CPUID的幾种方法

    第一种:API: 
      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   
        
      
    Public   Function   GetCPUid()   As   String   
        
              
    On   Error   GoTo   doError   
                
              
    Dim   len5   As   Long,   aa   As   Long   
              
    Dim   cmprName   As   String   
              
    Dim   Computer   As   String   
              
    Dim   CPUs   As   Object,   MyCpu   As   Object   
              
    Dim   osver   As   OSVERSIONINFO   
              
    Dim   SerialNo   As   String   
        
              
    '取得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   
                      SerialNo   
    =   MyCpu.ProcessorId   
                      
    Exit   For   
              
    Next   
              GetCPUid   
    =   SerialNo   
              
    Exit   Function   
      doError:   
              GetCPUid   
    =   ""   
        
    End   Function   
    第二种:使用类:
     'Microsoft   WMI   Scripting   V1.1   Library的引入   
        Public Function GetProcessorID() As String
          Dim a     As SWbemServices
          Dim b     As SWbemObjectSet
          Dim c     As SWbemObject
          Dim d     As SWbemPropertySet
          Dim e     As SWbemProperty
          Dim str As String
         
             
          Set a = GetObject("winmgmts:")
          Set b = a.InstancesOf("Win32_Processor")
          For Each c In b
                With c
                    If .Properties_.Count > 0 Then
                        Set d = .Properties_
                         
                        For Each e In d
                          If UCase(e.Name) = UCase("ProcessorId") Then
                              str = e.Value
                          End If
                           
                        Next
                    End If
                End With
          Next
          GetProcessorID = str
         
      End Function

    申明

    非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

    博文欢迎转载,但请给出原文连接。

  • 相关阅读:
    MySQL 函数
    ARC072_F Dam
    1373D
    科目二和科目三找准30厘米位置的点位
    MySQL 数字保留两位小数
    IntelliJ IDEA 中,项目文件右键菜单没有svn选项解决办法
    MySQL SQL语句书写顺序和执行顺序
    科目三道路驾驶技能考试之百米加减挡操作
    上海科目三道路驾驶技能考试夜间灯光模拟操作
    上海 科目三大路考试攻略
  • 原文地址:https://www.cnblogs.com/Athrun/p/1238426.html
Copyright © 2011-2022 走看看